Calculating Time Duration Across Midnight, and the Real Leap Year Rule
How to calculate elapsed time when it wraps past midnight, and the three-part rule that actually governs leap years.
Time duration and leap year calculations both look like they should be trivial — until you hit the specific edge case each one is actually designed to handle correctly.
Time duration: what happens past midnight
For same-day times, duration is simply End Time − Start Time. A 9:00 AM start (9.0) and 5:30 PM end (17.5) gives 17.5 − 9.0 = 8.5 hours. But a shift that starts at 9:00 PM and ends at 5:00 AM the next day needs different handling — since 5.0 is numerically less than 21.0, a naive subtraction would produce a negative, meaningless result. The correct approach adds 24 hours whenever the end time is numerically smaller than the start time: (5 + 24) − 21 = 8 hours, correctly wrapping across midnight.
The real leap year rule (it's three rules, not one)
"Every 4 years" is only the first layer. The complete rule: a year is a leap year if divisible by 4, except century years (divisible by 100), unless they're also divisible by 400.
- 2024: divisible by 4, not a century year → leap year
- 1900: divisible by 4 and by 100, but not by 400 → not a leap year
- 2000: divisible by 4, by 100, and by 400 → leap year
- 2100 (a future case): divisible by 4 and by 100, but not by 400 → not a leap year
Why the three-tier rule exists at all
Earth's actual orbital period is approximately 365.2422 days, not exactly 365.25. Adding a leap day every 4 years (365.25 average) overcorrects slightly; skipping leap years on century years (except those divisible by 400) fine-tunes the average back down to 365.2425 days — extremely close to the true value, keeping the calendar aligned with the seasons over centuries.
Common mistakes to avoid
- Applying the "every 4 years" rule without the century-year exception, which silently miscalculates leap status for years like 1900 or 2100
- Forgetting to add 24 hours when a duration calculation wraps past midnight, producing a negative or nonsensical result
- Assuming "business days" calculations already exclude public holidays — they typically only exclude weekends unless explicitly extended to do more
Calculate your own duration and leap year checks with the time duration calculator and leap year checker.