Compare two dates using javascript

Rajni.Shekhar
Posted by Rajni.Shekhar under JavaScript category on | Points: 40 | Views : 3391
function DateCompare(startDate, endDate) {
var str1 = startDate;
var str2 = endDate;
if (Trim(str1) != '' && Trim(str2) != '') {
var yr1 = parseInt(str1.substring(6, 10), 10);
var mon1 = parseInt(str1.substring(3, 5), 10);
var dt1 = parseInt(str1.substring(0, 2), 10);

var yr2 = parseInt(str2.substring(6, 10), 10);
var mon2 = parseInt(str2.substring(3, 5), 10);
var dt2 = parseInt(str2.substring(0, 2), 10);
var startDate1 = new Date(yr1, mon1, dt1);
var endDate1 = new Date(yr2, mon2, dt2);
if (startDate1 > endDate1) {
return false;
}
}
return true;
}

Comments or Responses

Login to post response