I’m using custom plugin for jQuery UI datepicker – Timepicker
I have two fields, from and to input field, and need to check if to “is greater than” from. I have my custom onClose function (onClose: function(dateText, inst) {}), but the first parameter is value of input – a date string. But my date string is not in the “valid” JS datetime format so I’m not able to get Date object instance and compare.
It’s dd.mm.yyyy hh:mm, e.g. 06.08.2012 12:00
I wonder if there is anything how to specify input string format, e.g.:
var date = new Date('dd.mm.yyyy hh:mm', dateText);
If not I’ll have you parse it somehow…
Thanks for help in advance.
There is no such utility built in to JavaScript. If I were you I would match the date format with a regex and use the form of the Date constructor which accepts date parts:
Note that the month part is zero based (instead of one based, so January=0, hence the minux one). Also, note that the
Numberconstructor is used to convert strings to numbers so you don’t have to worry about numbers possibly prefixed with a zero being interpreted as octal as can happen withparseInt(...).