Q: How to get a difference between two dates? 
Possible Duplicate:
How do I get the difference between two Dates in JavaScript? 

How to get the difference between two dates using javascript.I need the exact day difference between those two dates.Here is my code
function calculateDifference() {
var startDate = document.getElementById("MainContent_txtOStartDate").value;
var endDate = document.getElementById("MainContent_txtOEndDate").value;
return DateDiff(startDate, endDate);
}

function DateDiff(startDate, endDate) {
var a = Date.parse(startDate) - Date.parse(endDate);
alert(a);
}

Any suggestion?

A: ​var date1 = new Date(2012, 2, 28, 1, 1, 1);
var date2 = new Date(2012, 2, 22, 1, 1, 1);

alert(date1);
alert(date2);

var sec = 1000;
var min = sec * 60;
var hour = min * 60;
var day = hour * 24;

var dateDiff = (date1 - date2) / day;

alert('Difference in days: ' + dateDiff);

​

