in Advanced 

Question preview

HomeQuestion preview:
Log in

How to calculate difference between two dates

How to calculate difference between two dates

For example

"July 21, 1983 01:15:00" and "March 21, 1993 01:25:02"
Do you know someone who could answer? Ask him for help
Answers: 1
Sort by: date rating
image maverix
23:14/28.10.2010
5 from possible 5 with 1 votes
var beginDate = new Date(2010, 0, 1); //January the first, 2010
var endDate = new Date(2010, 11, 31); //December 31, 2010

var oneDay = 1000 * 60 * 60 * 24; //in milliseconds

var totalDaysThisYear = (endDate.getTime() - beginDate.getTime()) / oneDay;


getTime returns the milliseconds from 1st January 1970 to the specified date, so we subtract the 2 dates this way and divide by the milliseconds that represent one day to get the result in days.
Vote:
Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
Ask question
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |