Key takeaways
- A date is a number. Duration is subtraction on day numbers, not on month names.
- Exclusive is the default. 2026-01-01 to 2026-03-01 is 59 days; inclusive is 60.
- State the convention. Hotels count nights, payroll counts days worked, statutes count clear days.
- Leap years change the total. A leap day inside the span adds exactly one.
- Subtract dates, not local timestamps. A DST day is 23 or 25 hours, so dividing elapsed seconds by 86,400 breaks.
Two questions hide behind “days between”
“How many days between January 1 and March 1?” has two defensible answers. The first counts the days that have to elapse: start on January 1, and March 1 arrives 59 days later. The second counts how many calendar dates the interval covers, including both ends: 60.
The distinction is not pedantry. A hotel stay from January 1 to March 1 is 59 nights, and the guest checks out on the 60th day without occupying it. A conference that runs January 5 to January 7 is a 3-day event, not a 2-day one. Payroll for days worked includes both the first and last day. Every duration bug starts with somebody assuming the wrong convention, so write the convention down before computing.
Direction matters too: end minus start is negative when the end date is in the past, so tools display an absolute value and keep the sign internally.
A date is already a number
The Gregorian calendar assigns every date a unique integer. The most useful is the epoch day number: days since 1970-01-01, which is day 0; 1969-12-31 is day −1. Under that scale, 2026-01-01 is 20,454, 2026-11-14 is 20,771, and 2027-02-12 is 20,861.
You can compute a day number from year, month, and day without a loop. Using integer division throughout, the steps are:
- If the month is January or February, subtract 1 from the year and add 12 to the month, so the year starts in March.
- Let era = floor(year ÷ 400) and yoe = year − 400 × era, which lands in 0 through 399.
- Let doy = (153 × (month − 3) + 2) ÷ 5 + day − 1, the day of the 400-year cycle’s year.
- Let doe = 365 × yoe + yoe ÷ 4 − yoe ÷ 100 + doy.
- The day number is 146,097 × era + doe − 719,468.
For 2026-11-14 that gives era 5, yoe 26, doy 258, doe 9,754, and 730,485 + 9,754 − 719,468 = 20,771. The constant 146,097 is the number of days in a 400-year Gregorian cycle — exactly 20,871 weeks — and 719,468 shifts the epoch from 0000-03-01 to 1970-01-01. The formula handles every date in the proleptic Gregorian calendar, including dates before 1970, and it needs no month-length table.
The subtraction, step by step
Start 2026-11-14, end 2027-02-12. Epoch day 20,861 minus 20,771 equals 90 days. The same total can be checked by hand in month-sized pieces: 16 days remain in November after the 14th, then 31 in December, 31 in January, and 12 in February. 16 + 31 + 31 + 12 = 90.
Adding the duration back confirms the answer: 2026-11-14 plus 90 days is 2027-02-12. Any duration that does not survive that round trip is wrong, and the check costs nothing.
For a signed result, compute end − start: the magnitude is the duration and the sign says which date is later.
Inclusive counting and the +1 rule
If both endpoints count, add one to the exclusive difference: 2026-01-01 to 2026-03-01 is 59 + 1 = 60 calendar dates. A three-day conference from January 5 through January 7 has an exclusive difference of 2 and an inclusive count of 3.
Written rules usually say which one applies. Procedural deadlines commonly exclude the day of the triggering event and include the last day, so a 30-day period that starts on January 1 ends on January 31. “Clear days” excludes both endpoints and is shorter than the same number of ordinary days. “Within 10 days” is ambiguous until you find the definition, and a deadline that lands on a weekend or holiday often rolls to the next business day.
When a contract is silent, count the way the parties have counted before, and record the assumption next to the number.
Leap years change the total
From 2026-01-01 to 2026-03-01 there are 59 days, because 2026 is a common year and February has 28 days. From 2024-01-01 to 2024-03-01 there are 60, because 2024 is leap and February has 29. The leap day sits inside the span, so the difference is exactly one day.
The Gregorian rule is divisible by 4, except centuries not divisible by 400. That is why 1900-01-01 to 2000-01-01 is 36,524 days while 2000-01-01 to 2100-01-01 is 36,525: the second century contains the leap day of February 29, 2000, and the first contains no leap day in 1900. Two spans of 100 years, one day apart.
The consequence for duration work is simple: never estimate a multi-year span as 365 × years. Either use day numbers or add the leap days explicitly.
Time zones, midnight, and DST
Date-only arithmetic has no clock, so it cannot be affected by a time zone — provided you keep it date-only. The trouble starts when a date is stored as midnight local time and then converted. A timestamp of 2026-11-14 00:00 in UTC+13 is 2026-11-13 11:00 UTC, and any code that formats that instant in UTC reports the wrong date.
If you must subtract timestamps, convert both to UTC first and then take the difference in whole days. Do not divide local elapsed seconds by 86,400: in a daylight-saving region one local day each spring lasts 23 hours and one each autumn lasts 25, so the division yields 0.958 or 1.042 and truncates to the wrong integer.
Midnight itself is a boundary, not a duration. A date covers 00:00:00 through 23:59:59.999 in its zone. Database queries that use “less than the next date at midnight” are inclusive of the whole day; queries that use “less than or equal to 23:59:59” silently drop the final second.
Dates before 1970 and far ahead
Epoch day numbers are signed, so 1900-01-01 is −25,567 and 1969-12-31 is −1. Nothing special is required as long as the arithmetic uses signed integers and the proleptic Gregorian calendar — the same rules extended backward before 1582.
Watch the storage format instead. A 32-bit signed Unix timestamp overflows in January 2038, and a date library that stores years in two digits breaks at century boundaries. ISO 8601 date strings such as 2026-11-14 sort correctly as text and have no range problem for any date you will encounter.
Leap seconds are a separate matter. UTC occasionally inserts a second, making a civil day 86,401 seconds long, but the calendar date still advances by one. Date counting ignores leap seconds entirely; only sub-second timekeeping needs them.
Business days are a different count
Calendar days are every date. Business days skip weekends and whatever holidays the relevant jurisdiction observes, so a 10-business-day span can run two calendar weeks or longer. Observed holidays move: a holiday that falls on Saturday may be observed on Friday, and one that falls on Sunday on Monday.
If a deadline is expressed in business days, convert it with a holiday list for the right country and year, and confirm whether the count includes the start day. The arithmetic is the same; only the countable days change.
Common mistakes
- Counting both endpoints when the question asked for elapsed days, or the reverse.
- Estimating months as 30 days and years as 365.
- Dividing elapsed seconds by 86,400 across a DST transition.
- Parsing 01/02/2026 as January 2 in one place and February 1 in another.
- Converting a date to a UTC timestamp and formatting it back into a date.
- Forgetting that February 29 exists when hand-checking a total.
- Treating a stored 23:59:59 as the end of a day in a query.
Worked examples
| Start | End | Exclusive days | Inclusive count |
|---|---|---|---|
| 2026-01-01 | 2026-03-01 | 59 | 60 |
| 2024-01-01 | 2024-03-01 | 60 | 61 |
| 2024-02-28 | 2024-03-01 | 2 | 3 |
| 2026-11-14 | 2027-02-12 | 90 | 91 |
| 1900-01-01 | 2000-01-01 | 36,524 | 36,525 |
| 2000-01-01 | 2100-01-01 | 36,525 | 36,526 |
The 2024-02-28 row is the smallest leap-year case: the two-day gap exists only because February 29 sits between the dates. In 2026 the same pair of month-end dates would be one day apart.
Frequently asked questions
Is “days between” inclusive or exclusive?
By default it is exclusive: the start date does not count, the end date does. Add one if both endpoints should count.
How do I count days between two dates by hand?
Add the days remaining in the first month, whole months in between, and the day number in the last month. Or convert both dates to day numbers and subtract.
Does a leap year always add a day?
Only if February 29 falls inside the interval. A span from March to October in a leap year is unaffected.
Why is my spreadsheet off by one?
Spreadsheet date functions usually subtract serial numbers, which is exclusive, while the display or a manual count may include both ends.
Can I just divide hours by 24?
Only if the hours are measured in UTC. Local hours across a DST change total 23 or 25 for a calendar day.
How many days are in a year?
365 in a common year and 366 in a leap year. The average over the 400-year Gregorian cycle is 365.2425.
Further reading
Keep exploring
Decision path