How can i check the date picker date which are selected is less than current date.
My date picker formate is [MON d,YYYY] Like [Feb 6, 2012],
if i pick up old date in textbox how can i check this date is less than current date.
How can i check the date picker date which are selected is less than current date.
My date picker formate is [MON d,YYYY] Like [Feb 6, 2012],
if i pick up old date in textbox how can i check this date is less than current date.
Use $.datepicker.parseDate(format, string)
to turn your date in to JavaScript Date, get current date by var now = new Date();
After that, You can just use <
operator to check whether the date picked is less than the current date.
EDIT: Assuming you are using jquery ui date picker
This seems to do the trick...
var isFutureDate = new Date < new Date(
str
.match(/^\[(\w{3})\s(\d+),\s(\d{4})\]$/)
.slice(1)
.join(' ')
);
This creates a new Date
object which defaults to the current client time, and then constructs a second Date
object passing a modified version of your user input which can be parsed by the Date
constructor. The <
operators calls the valueOf()
of both dates, which returns the milliseconds since the Unix epoch (equivalent of calling getTime()
).
You could take into account leading and trailing whitespace on the input by using $.trim()
or wrapping the regex with \s*
.
You could swap new Date
with $.now()
, which is slightly fewer characters