Skip to content
Mycelgrid

Method guide

How to Calculate Duration Between Two Dates and Times

Validate both Gregorian dates, convert each date to an ordinal day and each time to seconds after midnight, then subtract Start from End and decompose the exact seconds.

Quick answer

Build a civil timestamp for each endpoint: ordinal day × 86,400 + seconds after midnight. The duration is End − Start. End must be on or after Start.

1. Validate both dates

Use the proleptic Gregorian calendar. Month lengths must be valid, Year 0000 is excluded, and February depends on the leap-year rule.

2. Apply the Gregorian leap-year rule

A year divisible by 4 is a leap year, except a year divisible by 100 is not, unless it is also divisible by 400. Thus 2000 was a leap year; 1900 and 2100 are not.

3. Convert each date to an ordinal day

Count whole days before the year, add days before the month, then add the zero-based day within the month. This produces a deterministic integer day position without invoking local timezone behavior.

4. Convert each time to seconds

Use hour × 3600 + minute × 60 + second. If seconds are omitted, use zero.

5. Compute End minus Start

For each endpoint, combine its ordinal day and time. Subtract the Start civil seconds from the End civil seconds. A negative value is invalid; zero is valid.

6. Decompose the duration

Divide the non-negative total by 86,400 for whole days, then by 3,600 for hours, 60 for minutes, and use the final remainder as seconds.

7. Calculate total units

Total seconds is exact. Divide by 60, 3,600, or 86,400 for total minutes, hours, or days. Mycelgrid rounds these ratios half-up to at most six decimal places.

Worked multi-day example

2026-10-17 08:30:00 to 2026-10-20 15:54:15 equals 3d 7h 24m 15s, 285,855 seconds, 4,764.25 minutes, 79.404167 hours, or 3.308507 days.

Worked leap-day example

2024-02-28 23:30:00 to 2024-03-01 00:15:30 equals 1d 0h 45m 30s. The date arithmetic includes February 29.

Equal timestamps and reversed endpoints

Equal endpoints produce zero elapsed duration. If End precedes Start, the interval is invalid until the endpoints are corrected.

Why a day is fixed at 24 hours here

The method is timezone-free civil arithmetic. It does not inspect location, UTC offset, or daylight-saving transitions. Every duration day is therefore exactly 86,400 seconds.

Why months and years are not duration units

Calendar months and years have variable lengths, so this calculator does not present them as fixed elapsed-duration units. Use date arithmetic when the job is adding calendar months or years.