How do you calculate the difference between two dates in days?
Short answer
Subtracting two Date objects (or calling getTime() on each) yields the difference in milliseconds; divide by the number of milliseconds in a day (1000*60*60*24) to get whole days.
Advertisement
AModel answer
Subtracting two Date objects (or calling getTime() on each) yields the difference in milliseconds; divide by the number of milliseconds in a day (1000*60*60*24) to get whole days.
const start = new Date('2026-08-01');
const end = new Date('2026-08-08');
const days = (end - start) / (1000*60*60*24); // 7Real-world example
Calculating how many days remain until a subscription renews.
Likely follow-ups
- Why can this calculation be off by an hour around daylight saving time changes?
Related topics