Home › Forums › JavaScript › Need to calculate the no of days between two dates? › Re: Need to calculate the no of days between two dates?
April 19, 2009 at 5:30 pm
#56555
chazzwick
Member
a little googling gave me this code:
Code:
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2009,04,21);
var secondDate = new Date(2009,04,25);
var diffDays = Math.abs((firstDate.getTime() – secondDate.getTime())/(oneDay)); //this calculates the number of days between firstDate and secondDate
I tested it out, and it did give the answer as 4