How can I get the difference between two dates?
I have:
date1 = 2014/2/20
date2 = 2014/2/16
I want to get the difference value as 4
.
How can I get the difference between two dates?
I have:
date1 = 2014/2/20
date2 = 2014/2/16
I want to get the difference value as 4
.
Try this to get the difference in terms of number of days
var date1= "2014/2/20";
var date2= "2014/2/16";
var difference = (new Date(date1) - new Date(date2))/(1000*60*60*24);
var oneDay = 24 * 60 * 60 * 1000;
function getDateDiffinDays(d1, d2) {
var firstDate = new Date(d1);
var secondDate = new Date(d2);
return Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / (oneDay)));
}
alert(getDateDiffinDays('2014/2/20', '2014/2/16'));
You may simply get the day month and year from the date using js methods as getMonth,year etc. after this you can sinply subtract.