Date Difference Calculator — Days, Weeks, Months, Years
Find the exact gap between two dates broken down into years, months, days, weeks, hours, and minutes — plus a working-days count that strips out weekends. Leap-year accurate, DST-aware, runs entirely in your browser.
How it works
The calculator answers two related questions: how many days separate two dates, and how that gap reads as a calendar duration like "2 years, 3 months, 5 days". Both use the half-open interval [start, end) — the start date is day zero and the end date itself is not counted, so 1 Jan to 2 Jan is exactly one day. This is the same convention used by the date-fns library and by mainstream date calculators such as timeanddate.com and calculator.net.
For the day count, the algorithm converts each input to a UTC-midnight day number — the number of whole days since 1 Jan 1970 UTC — and subtracts. Using UTC sidesteps daylight-saving transitions, so a day in a region that shifts the clock still counts as exactly one day. The same day numbers feed the working-days count: each whole week in the interval contributes five weekdays, and the remaining 0–6 days are checked one by one against their day-of-week to decide whether each is a weekend or a weekday.
For the calendar-aware breakdown, the algorithm follows the date-fns differenceInMonths anniversary rule. Given start S and end E:
- Compute raw month gap:
M = (E.year − S.year) × 12 + (E.month − S.month). - If
E.day < S.day(the anniversary hasn't arrived in the final month), subtract one fromM. - Split into years and months:
years = ⌊M / 12⌋,months = M mod 12. - Build an anchor date
S + M months, clamping the day-of-month to the last day of the resulting month (so adding one month to 31 Jan gives 28 Feb in a non-leap year, not 3 Mar). - Count days from the anchor to
E. The breakdown reconciles exactly:S + Y years + M months + D days = E.
To guard against single-algorithm bugs, the total-days figure is cross-checked against a second implementation that counts UTC midnights independently, and the Y/M/D breakdown is verified by adding it back to the start date — both checks must pass before the "cross-checked" badge appears in the calculator header.
For leap-year inputs the Gregorian rule applies in full — years divisible by 4 except centuries unless divisible by 400. That makes 2000 a leap year but 1900 not, and 2024 leap but 2025 not. The Sri Lanka Registrar General's practice of rolling Feb 29 anniversaries to Feb 28 in non-leap years is exactly what the anchor-clamp step produces here.
Worked examples
Frequently asked questions
Sources & references
- ECMA-262 — JavaScript Date object specification
- date-fns — differenceInMonths anniversary rule
- Gregorian calendar — leap-year rule (Wikipedia)
- ISO 8601 — duration format (PnYnMnD)
- Microsoft Excel — NETWORKDAYS function reference
Algorithm and worked examples last cross-checked on 2026-05-11. The calendar arithmetic doesn't change, so this page is reviewed annually rather than on a fixed schedule.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.