Duration Calculator
Pick a start and end date and instantly get the exact span in years, months, and days — plus total days, weeks, and hours — with a visual timeline, step-by-step breakdown, and clear handling of leap years and reversed dates.
Background
There are two common ways to measure the time between two dates: a straight total day count, and a calendar breakdown into whole years, whole months, and leftover days. These can feel inconsistent because calendar months have different lengths — this calculator computes both using real calendar dates, including leap years, so the breakdown is always accurate.
How to use this calculator
- Pick a start date and an end date, or check Until today to keep the end date locked to the current date.
- Toggle Include end day if you want the end date itself counted as part of the span — this is the most common point of confusion in date math.
- Click Calculate to see the years/months/days breakdown, total days, a visual timeline, and a full step-by-step explanation.
- Use the quick example chips to instantly load common scenarios, including a leap-year span and a reversed-date edge case.
How this calculator works
Total days. Counts the calendar days between the two dates using date-only timestamps (no time-zone or daylight-saving drift). If "Include end day" is on, 1 day is added so the end date itself is counted.
Calendar breakdown (years, months, days). Starting from the start date, the calculator finds the largest number of full years that still land on or before the end date, then the largest number of full months, then counts whatever days are left over. This respects real month lengths (28–31 days) and leap years automatically — it isn't a fixed conversion from total days.
Reversed dates. If the end date is earlier than the start date, the calculator swaps them (when enabled) so you still get a valid, correctly signed result instead of an error.
Formula & Equations Used
Total days (exclusive): days = UTC(end) − UTC(start), measured in whole calendar days using date-only UTC timestamps to avoid time-zone drift.
Inclusive option: days_inclusive = days_exclusive + 1
Calendar breakdown: accumulate the largest whole number of years that still lands on or before the end date, then the largest whole number of months from there, then whatever days are left over.
Weeks: weeks = ⌊days_total / 7⌋, with the remainder shown as leftover days.
Hours: hours = days_total × 24
Example Problems & Step-by-Step Solutions
Example 1 — Age calculation
Born 2000-01-01, today is 2026-06-30.
Step 1: Full years from 2000-01-01 to 2026-01-01 = 26 years.
Step 2: From 2026-01-01, full months to 2026-06-01 = 5 months.
Step 3: From 2026-06-01 to 2026-06-30 = 29 days.
Result: 26 years, 5 months, 29 days (9,676 total days).
Example 2 — Leap year span
2020-02-29 (a leap day) to 2025-02-28.
Step 1: 2025 is not a leap year, so February only has 28 days — there's no 2025-02-29 to land on.
Step 2: The calculator clamps to the last valid day of the target month, giving exactly 4 years, 11 months, 28 days.
Why it matters: Naive date math that just adds "1 year" repeatedly can throw an error or silently miscount on leap days — this calculator handles it correctly.
Example 3 — Inclusive vs. exclusive counting
Start and end date are both 2026-06-30 (the same day).
Exclusive (default off): 0 total days — nothing has elapsed between identical dates.
Inclusive (Include end day on): 1 total day — the single day itself is counted.
Why it matters: This is the single most common source of "off by one" errors when counting deadlines or rental periods.
Example 4 — Reversed dates (edge case)
Start date accidentally entered as 2026-06-30, end date as 2025-01-01.
Step 1: The calculator detects the end date is earlier than the start date.
Step 2: With auto-swap enabled, it swaps them and recalculates using 2025-01-01 as the true start.
Result: A valid duration is returned instead of an error, with a note explaining the swap.
Frequently Asked Questions
Why do "total days" and "years/months/days" give different impressions?
Total days is a straight count. The years/months/days breakdown is calendar-based — since months have different lengths (28 to 31 days), dividing total days evenly wouldn't match the real calendar. This calculator always computes the calendar breakdown from actual dates, not from total days.
What does "Include end day" actually change?
It decides whether the end date itself counts as an elapsed day. If start and end are the same date, exclusive counting gives 0 days; inclusive counting gives 1 day. This matters most for things like rental periods, "how many days am I traveling," or attendance counts.
Why does this calculator swap reversed dates instead of erroring out?
Accidentally entering the later date as the start date is one of the most common data-entry mistakes. Auto-swapping (when enabled) prevents a confusing error message and still gives you the correct, intended duration — with a note confirming what happened.
How are leap years handled?
Because the calculator works directly with real JavaScript calendar dates rather than a fixed "365.25 days per year" approximation, leap years are handled automatically and exactly — February 29 is correctly recognized in leap years and skipped in non-leap years.
What's a good use case for "Until today"?
Age calculations, "how long have I been at this job," anniversaries, and countdowns since an event all benefit from "Until today" — it keeps the end date current without you having to manually update it every time you reopen the calculator.
Why might weeks and hours look like odd numbers?
Weeks are calculated as total days ÷ 7, rounded down to a whole number — so a span of 10 days is reported as 1 week (with 3 days left over, visible in the years/months/days breakdown). Hours are simply total days × 24, since every full day has exactly 24 hours regardless of daylight-saving shifts in this date-only calculation.