Function to compare two dates

Virendradugar
Posted by Virendradugar under JavaScript category on | Views : 8295
function CompareDates(str1,str2) 
{
if(str1 == "")
return false;
var dt1 = parseInt(str1.substring(0,2),10);
var mon1 = parseInt(str1.substring(3,5),10);
var yr1 = parseInt(str1.substring(6,10),10);
var dt2 = parseInt(str2.substring(0,2),10);
var mon2 = parseInt(str2.substring(3,5),10);
var yr2 = parseInt(str2.substring(6,10),10);
mon1 = mon1 -1 ;
mon2 = mon2 -1 ;
var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);

if(date2 >= date1)
{
return false;
}
else
{
return true;
}
}

Comments or Responses

Login to post response