How can I compare a "MM/DD/YYYY" date with the Date() function in Javascript? -


how can compare date input of format "mm/dd/yyyy" date() function in javascript?

for example:

if (inputdate < todaysdate){   alert("you entered past date") } else if (inputdate > todaysdate){   alert("you entered future date") } else if (inputdate = todaysdate){   alert("you entered present date") } else{   alert("please enter date") } 

convert string date using new date(datestring). normalize today's date omit time information using today.sethours(0, 0, 0, 0). can compare dates have above:

var date = new date(dateinput); if (isnan(date)) {     alert("please enter date"); } else {     var today = new date();     today.sethours(0, 0, 0, 0);     date.sethours(0, 0, 0, 0);     var datetense = "present";     if (date < today) {         datetense = "past";     }     else if (date > today) {         datetense = "future";     }     alert("you entered " + datetense + " date"); } 

demo: http://jsfiddle.net/w2sjd/


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -