I saw this fiddle for validating mm/dd/yyyy or mm-dd-yyyy
but I would like to validate yyyy-mm-dd hh:mm:ss
format also how do I ensure that today is lesser than from date with the yyyy-mm-dd hh:mm:ss
format?.
this is how I have initiated my date time picker..
$("#startDate, #endDate").datetimepicker({ dateFormat: 'yyyy-mm-dd hh:mm:ss'});
Please do help me to get this done.
Thanks
Checking
yyyy-mm-dd hh:mm:ss
strings against each other is pretty easy because they're already in order; you can forget about what base the numbers are in and simply do<
or>
as in string comparison. This may not work with other dates.Validating dates is a bit more complicated, because the number of days in months can change. You can ignore this fact and just test for digits, but I prefer meeting half way, introducing upper limits.
So for example using it
Now all that is left is to get the value from your inputs.
For 24 hour variation, instead of AM/PM, use:
Change your RegExp inside the ValidateDate function to below code
try this and let me know, same way u can validate the hh:mm:ss also
The date format that you have specified is ISO 8601. Most modern browsers support
Date
parsing of this string format. So you can do something like this.Javascript
jsFiddle