Why doesn't this work right?
function test() {
var start = new Date(2012, 3, 31, 19, 0, 0); // 3/31/2012 7:00 PM
var end = new Date(2012, 4, 1, 1, 0, 0); // 4/01/2012 1:00 AM
if (end < start)
console.log("oops!");
else
console.log("works!");
}
Output:
oops!
Months are 0-based in js
var start = new Date(2012, 2, 31, 19, 0, 0); // 3/31/2012 7:00 PM
var end = new Date(2012, 3, 1, 1, 0, 0); // 4/01/2012 1:00 AM
In your case both start and end are 1 May 2012. Just output the values and you'll see.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With