Skip to content
Mycelgrid

Guide

How to Calculate Days Between Dates

A deterministic date difference can be calculated without timestamps, timezones, or daylight-saving rules by converting each Gregorian civil date to an integer ordinal day.

1. Validate the Gregorian dates

Each endpoint must be a real date in the proleptic Gregorian calendar. The leap-year rule is divisible by 4, except century years unless divisible by 400. This is why 1900 is not a leap year while 2000 is.

2. Convert each date to an ordinal day

An ordinal day assigns one integer to each civil date. In this app 0001-01-01 is ordinal 0. The elapsed day difference is then ordinal(End) − ordinal(Start).

That means the same date to itself is 0 elapsed days. If you need to count both calendar dates, the inclusive date count is elapsed days + 1.

3. Express weeks and days

Whole weeks are the elapsed day difference divided by 7. The remainder is the extra days. No decimal-week approximation is needed.

4. Express calendar years, months, and days

Years and months are variable-length calendar units. Find the largest whole-month displacement from Start that does not pass End, using month-end constraining. Split that displacement into years and months, then count the remaining ordinal days.

Worked examples

Leap-day interval: 2024-02-28 → 2024-03-01 is 2 days. Century rule: 1900-02-28 → 1900-03-01 is 1 day, while 2000-02-28 → 2000-03-01 is 2 days.

Calendar span: 2006-08-24 → 2019-01-31 is 4,543 elapsed days and a calendar difference of 12 years, 5 months, 7 days.

Adding and subtracting dates

For date addition, combine years and months into one calendar-month displacement, constrain the original day to the last valid day in the target month, then apply weeks × 7 + days as exact ordinal days. This prevents repeated-month drift.

Boundaries

If End precedes Start, this calculator reports an error and offers Swap rather than taking an absolute value. Business days, holidays, time-of-day, timezones, and age calculations are separate jobs.