Back to results for “Time & Internationalization (Intl API)”
JavaScript › Date, Time & Internationalization (Intl API)

How do you calculate the difference between two dates in days?

Intermediate

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); // 7
Real-world example Calculating how many days remain until a subscription renews.

Common follow-ups: Why can this calculation be off by an hour around daylight saving time changes?