Skip to main content

Duration Calculator

Pick a start and end date and instantly get the exact span in years, months, and days, or in months only or days only, plus 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. You can also read the answer in months only (for example, 317 months and 29 days) or days only (9,677 days).

Calculate the duration

Step 1 — Choose your dates

Pick a start date and an end date, or check "Until today" to always measure up to the current date. For an age, use the birth date as the start date and tick "Until today".

Step 2 — Options

Result

No result yet. Choose your dates above and click Calculate.

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. To find an age, use the birth date as the start date.
  • Leave Count the end date too off for ages and "time since" questions. Turn it on when the first and last day both count, such as a trip or a rental period — this is the most common point of confusion in date math.
  • Click Calculate to see the years/months/days breakdown, the answer in months only and days only, a visual timeline, and a full step-by-step explanation.
  • Use the quick example chips to load sample scenarios, including a leap-year span and a reversed-date edge case. They use sample dates, not yours.

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 the end date is counted too, 1 day is added.

Calendar breakdown (years, months, days). Starting from the start date, the calculator finds the largest number of whole months that still lands on or before the end date, splits that into years and 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. When a start day doesn't exist in a shorter month (the 31st, or February 29), it lands on the last valid day of that month.

Months only. The same whole months, without splitting them into years: years × 12 + months, plus the leftover days. For 26 years and 5 months that is 317 months.

Days only. The plain count of days between the two dates (9,677 for the same span), with the end date included when that option is on.

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: find the largest whole number of months that still lands on or before the end date, then years = ⌊months ÷ 12⌋ and months = months mod 12, with whatever days are left over.

Months only: total months = years × 12 + months, plus the leftover days

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,677 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: Adding 5 years to 2020-02-29 is clamped to the last valid day of the month, 2025-02-28, which is exactly the end date.

Result: exactly 5 years, 0 months, 0 days (1,826 total 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 — Counting the end date or not

Start and end date are both 2026-06-30 (the same day).

Not counted (the default): 0 total days — nothing has elapsed between identical dates.

Counted (the option is 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. For an age, leave it off: otherwise someone one day short of a birthday would already show the older age.

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.

Example 5 — Months only

2024-01-15 to 2025-04-10.

Step 1: The largest whole number of months that lands on or before 2025-04-10 is 14 (2024-01-15 + 14 months = 2025-03-15).

Step 2: From 2025-03-15 to 2025-04-10 = 26 leftover days.

Result: 14 months, 26 days in months only — the same span as 1 year, 2 months, 26 days.

Frequently Asked Questions

Can I get the answer in months only, or days only?

Yes. Every result shows an "In months only" line (for example, 317 months, 29 days) and an "In days only" line (for example, 9,677 days), plus Total months and Total days cards. Months only is the same whole months as the years/months/days breakdown, with the years converted: years × 12 + months.

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 "Count the end date too" actually change?

It decides whether the end date itself counts as an elapsed day. It is off by default, which is right for ages and "time since" questions. If start and end are the same date, leaving it off gives 0 days and turning it on gives 1 day. Turn it on for trips, rentals, or attendance, where both the first and last day count.

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. If a start date is February 29 (or the 31st), a later month that is too short uses its last valid day, so February 29, 2020 plus 5 years is February 28, 2025.

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.

Back to all calculatorsAll calculators