Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need to calculate the no of days between two dates? Re: Need to calculate the no of days between two dates?

#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