CalculatorsLesson 169Free preview
Date Difference
This lesson is part of Web Developer Tools · All levels
Summary
Date Difference calculates the distance between two dates in a day, week, month, or year. If the date is calculated as a pure date, the difference in days can be obtained from the millisecond epoch divided by 86,400,000. Note whether the end dates are inclusive, as the January 1 to January 2 difference can mean one or two days depending on custom.
Key points
- The difference between day = (date - date1)/86,400,000 milliseconds
- Use UTC or a date without a clock so that DST doesn't shift the results.
- Inclusive means both dates are counted
- Months and calendar years are not equal to 30 or 365 days
- Workdays excluding weekends and holidays
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.