I am using Javascript Date.parse()
to check if a start time is after an end time.
The time in question is like this:
Date.parse("12:0
What version of IE are you testing this on? IE8 correctly returns false for me.
You can not just pass a time to Date.parse()
, as it is expecting a datestring. If you flip the >
in your code to a <
, you'll notice it still returns false
. This is because Date.parse()
is returning NaN
.
Try this:
var a = new Date("January 1, 1970 12:00:00");
var b = new Date("January 1, 1970 21:30:00");
if (a > b) { alert(true); } else { alert(false); }
if (a < b) { alert(true); } else { alert(false); }
The docs for Date.parse()
in IE state the following:
If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
For a cross-browser solution, you should avoid parse() and parse the time string manually. Alternatively, you could use a cross-browser library for parsing dates/times - DateJS is a popular one.