Tuesday, 26 June 2012

How to find difference between two dates in JavaScript?

var fromDate = new Date(document.getElementById('date1').value);
(or)
var d = new Date("15/02/2011");
alert(d.getTime());
alert(Date.parse(d));
var toDate = new Date(document.getElementById('date2').value);
var daysDifference = Math.ceil((toDate.getTime() - fromDate.getTime()) / (1000 * 60 * 60 * 24));

No comments:

Post a Comment