Find Difference between two dates using javascript

Hi All,

Following is the script to find the differences of two dates.
This sample script let you know which date is greater than another.

You could use jquery for the same as follows :

// if you have #from id for from date
var startDate = new Date(jQuery('#from').val().replace(/-/g, '/')).getTime();
// if you have #to id for from date
var endDate = new Date(jQuery('#to').val().replace(/-/g, '/')).getTime();

if(startDate < endDate)
{
alert("endDate is greater than startDate");
// do something
}
else
{
alert("startDate is greater than endDate");
// do something else
}

Or

simple javascript as follows :

function dateDifference() {

var str1 = "14-11-2012";
var str2 = "20-10-2012";

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);
var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);
if(date2 < date1)
{
alert("Date1 is greater than Date2");
// do something
}
else
{
alert("Date2 is greater than Date1");
// do something else
}

}

Dont waste more time in googling. You can use same function.. :)
Good luck !!!!