Four answers to one question
"How long between these dates" has more than one correct answer, and the useful one depends on what you are counting:
- Total days — for interest, ages and elapsed time.
- Weekdays — for deadlines, notice periods and delivery estimates.
- Full weeks — for sprint counts and rotas.
- Calendar difference — years, months and days, the way a person says it.
Why days ÷ 30 is not months
Averaging month lengths gives an answer that is never exactly right for a specific pair of dates. From 31 January to 28 February is 28 days but no full calendar month; from 1 March to 1 April is 31 days and exactly one. The calendar figure here borrows from the previous month the way you would on paper, so "one month and two days" means what you expect it to.
The timezone bug this avoids
Subtracting two local timestamps to get a day count breaks whenever daylight saving falls between them: one of those days is 23 or 25 hours, and the division rounds the wrong way. Counting at UTC midnight sidesteps it entirely, which is why an autumn date range here does not come back a day short.
Questions
Are both dates counted?+
The total days figure is the gap between the dates, so 1 January to 2 January is one day. The weekday count is inclusive of both endpoints when they fall on a weekday, because that is how notice periods and delivery windows are normally counted. Check which convention your contract uses — they differ by a day.
Why is the calendar difference not just days ÷ 30?+
Months have different lengths, so any average is wrong for a specific pair of dates. The calendar figure counts real months: from 31 January to 1 March is one day over a month in calendar terms, and 29 days in total. Both answers are correct and they answer different questions.
Does it handle leap years and daylight saving?+
Yes. Days are counted at UTC midnight, so a clock change between the two dates cannot add or lose a day — a real bug in naive implementations that subtract two local timestamps. Leap days are included because they are ordinary calendar days.
Are public holidays excluded from the weekday count?+
No. Holidays are jurisdictional and change every year, so the weekday figure is Mon–Fri only. Subtract your own public holidays from it if you need true business days.