I am trying to compare two dates using javascript with ExtJS 4.
var d= Ext.Date.parse("03/21/2012", "m/d/Y");
var comp= new Date();
if (d< comp) {
console.log("date value provided is larger" );
} else {
console.log("date value provided is less" );
}
When running the above example, the result I get is “date value provided is less”. However, when I change the value of d to a future date 12/21/2012, I still get the message “date value provided is less”.
I think this is because I need to format the var comp= new Date(); value so it can do the calculation.
How can I do that?
Both variables
dandcompare objects. They are instances ofDate.EDIT: Date objects can be compared using
<operator in JavaScript. Your code looks fine, it works on jsfiddle.Thanks for clarifying the date comparison in the comments.