how to compare two string dates in javascript?

var d1 = Date.parse("2012-11-01");
var d2 = Date.parse("2012-11-04");
if (d1 < d2) {
    alert ("Error!");
}

Demo Jsfiddle

Recently found out from a comment you can directly compare strings like below

if ("2012-11-01" < "2012-11-04") {
    alert ("Error!");
}

Leave a Comment