Back to Blog

Calculating duration between two dates and times

May 2, 2026
6 min read
Written by ConvertTime Team
durationcalculatortime-zonesdstfundamentals

How long is it between two dates? At first it seems simple — subtract one from the other. But edge cases mount: DST shifts can give a 23 or 25-hour day. Leap year February 29 throws off year math. Time zones complicate things further.

For computing exact duration between any two dates and times, the duration calculator handles all of these.

The basic concept

Duration = endtime - starttime.

Result can be expressed in:
- Days (most common)
- Hours
- Minutes
- Seconds
- Years + months + days (for human-readable)
- Years + months + weeks + days (more granular)

For programming purposes, most languages have date arithmetic libraries. For human use, the duration calculator is fastest.

Common calculations

Simple day count: 2026-05-21 to 2026-05-28 = 7 days.

With time component: 2026-05-21 14:30 to 2026-05-22 17:45 = 27 hours 15 minutes.

Years and months: 2020-05-21 to 2026-05-21 = 6 years 0 months 0 days.

Mixed: 2020-03-15 to 2026-05-21 = 6 years 2 months 6 days.

The duration calculator handles all of these.

DST complications

When the duration spans a DST shift, edge cases:

Spring forward (forward 1 hour): a 24-hour calendar day is actually 23 hours of clock time.
- 2026-03-08 00:00 EST to 2026-03-09 00:00 EDT = 23 hours of elapsed UTC time, but 1 calendar day.

Fall back (back 1 hour): a 24-hour calendar day is 25 hours of clock time.
- 2026-11-01 00:00 EDT to 2026-11-02 00:00 EST = 25 hours of UTC time, 1 calendar day.

For most practical uses, "1 day = 24 hours" is the right answer. The duration calculator gives both interpretations.

Leap year February 29

The Gregorian calendar has 365 days most years and 366 in leap years. February has 28 days (29 in leap years).

Edge cases:
- 2025-02-28 to 2025-03-01 = 1 day (no leap)
- 2024-02-28 to 2024-03-01 = 2 days (Feb 29 exists in 2024)
- 2024-02-29 to 2025-02-28 = 365 days (back to "same day" but 365 days, not 366)

The duration calculator handles leap years correctly. Test it with February 29 to verify.

Time zone considerations

For dates across time zones:

UTC math: convert both endpoints to UTC, subtract. Gives precise elapsed time, ignoring time zones.

Local math: subtract in local time. Misleading across DST changes (gives "calendar duration" but not "actual elapsed time").

Mixed-zone: pick a reference zone, convert both, subtract. Specify which zone.

The duration calculator defaults to UTC math but lets you specify zones.

Year-month-day breakdown

When expressing duration as "X years, Y months, Z days," there's ambiguity:

Approach 1 (simple): add Y months to start date, then count remaining days. Result: deterministic but sometimes feels weird.

Example: 2025-02-15 to 2026-04-30. From 2025-02-15:
- Add 14 months → 2026-04-15
- Remaining: April 15 to April 30 = 15 days
- Total: 1 year, 2 months, 15 days

Approach 2 (more careful): prefer ending on a "natural" day boundary if possible.

Most calculators use Approach 1.

Common practical scenarios

Pregnancy duration

"I'm 18 weeks pregnant" — calculated from last menstrual period (LMP), not conception:
- LMP date to today
- Standard medical calculation
- The duration calculator handles weeks specifically

Project duration

"This project has been running for 6 months and 3 days":
- Start date to today
- Express in years/months/days

Contract terms

"Service for 2 years from signing":
- Add 2 years to signing date
- The end date is 2 years later, same month and day (with leap-day adjustments)

Age (handled separately)

The age calculator (different from duration) handles "age in years from birth date" with calendar-aware semantics.

Working in different units

The duration calculator can express time in:

Largest-down: years, months, weeks, days, hours, minutes, seconds. Useful for human reading.

Total seconds: from start to end. Useful for arithmetic and exact comparisons.

Total days: simple integer count. Most common everyday use.

Calendar months: counting "month boundaries" rather than 30-day intervals. Important for legal/financial.

For most everyday use, days are most useful. For programming, total seconds is most precise.

Special considerations

Across centuries (e.g., 1900 to 2026)

Long durations have additional considerations:
- Pre-1582 dates use the Julian calendar; conversion needed
- Calendar reform shifted by 10-13 days in different countries at different times
- Most modern duration calculators only handle Gregorian dates (post-1582)

Across the international date line

If you fly from one side to the other, the calendar date changes but the duration is just hours of flight. The duration calculator handles this correctly using UTC.

Periods that include DST shifts

Duration is technically the elapsed UTC time, which doesn't change due to DST. The "calendar" interpretation does. The duration calculator can give either.

Tools for duration calculation

Browser-based:
- The duration calculator — clean and quick
- timeanddate.com — comprehensive
- calculator.net duration

Programming languages:
- Python: `(date2 - date1).days` (datetime objects)
- JavaScript: `(date2 - date1) / (1000 60 60 * 24)` (milliseconds)
- SQL: `date2 - date1` (PostgreSQL gives interval; format as needed)

Excel/Google Sheets: `=DAYS(date2, date1)` returns calendar days.

When the math feels wrong

Common reasons:

1. Off-by-one error: are you including both endpoints or just one? "From May 1 to May 5" is 4 days (5-1) or 5 days (inclusive of both). Be specific.

2. Mixed time zones: if start and end are in different zones, the "duration" depends on which interpretation you want.

3. DST shift in the middle: a 24-hour day might be 23 or 25 actual hours.

4. Leap year: February 29 throws off year math.

5. Calendar boundary: months have different lengths. "3 months from January 31" doesn't have a natural answer (April 30 or April 31?).

For all these, the duration calculator handles the conventions correctly.

FAQ

Why does the duration calculator show different results in different units?

Because of leap years and DST. "1 year" doesn't mean exactly 365 days. "1 day" doesn't always mean 24 hours. Different unit choices use different interpretations.

Can I calculate duration in business days?

The duration calculator computes calendar days. For business days specifically (excluding weekends and holidays), use the business days calculator instead.

What if my dates are in different time zones?

Specify both zones. The duration calculator uses UTC internally and gives the correct elapsed time regardless of input zones.

How are DST shifts handled?

Defaults: UTC math (DST shifts don't affect duration). The duration calculator lets you switch to "wall-clock" math if needed.

What about leap seconds?

Most duration calculations ignore leap seconds. They've added 27 seconds to UTC since 1972, but POSIX time and most date libraries don't include them. For 99% of uses, ignore leap seconds.

Can I include sub-second precision?

Some duration calculators support milliseconds or microseconds. For most everyday purposes, seconds is enough.

Bottom line

Duration calculation is straightforward in concept but has edge cases — DST shifts, leap years, time zones, calendar reforms. The duration calculator handles all of these correctly. For everyday use, calendar days are the most useful unit.

Share this article

Related Articles