How to Calculate Days Between Two Dates
Avoid DST, month-end rollover, and leap-year bugs when subtracting dates or adding months—plus calendar conventions in spreadsheets and JS.
Never compute calendar day counts by naive local timestamp division alone: Daylight Saving Time turns some days into 23 or 25 hours, and month-end additions (Jan 31 + 1 month) clamp differently by convention. Compute leap years and date offsets accurately using Date Add / Subtract.
You need to know how many days between two dates, or what date is 90 days from today, or how old a project is in weeks. The arithmetic looks simple. It is not, because of month-end rollover, leap years, and the fact that months have different lengths. This guide covers the rules, the edge cases, and the cleanest ways to do the math in a spreadsheet or a programming language.
The basic calculation: days between two dates
For two dates, the calculation is straightforward: subtract the earlier from the later.
In a spreadsheet
=B1 - A1
If A1 is the start date and B1 is the end date, the result is the number of days between them. Format the cell as a number, not a date, to see the result as a number of days.
In JavaScript
const start = new Date('2026-01-15');
const end = new Date('2026-08-15');
const days = (end - start) / (1000 * 60 * 60 * 24);
console.log(days); // 212
Subtracting two Date objects gives the difference in milliseconds. Divide by the number of milliseconds in a day (86,400,000) to get the number of days.
In Python
from datetime import date
start = date(2026, 1, 15)
end = date(2026, 8, 15)
days = (end - start).days
print(days) # 212
The result of subtracting two dates is a timedelta object; .days gives the day count.
In any language with a date library
Use the library's "diff" function. In moment.js, Luxon, date-fns, or any other date library, the API is end.diff(start, 'days') or similar. The library handles the math, including the edge cases below.
Adding or subtracting days
To add N days to a date, advance by N × 86,400,000 milliseconds, or use a date library.
In a spreadsheet
=A1 + 30
Adds 30 days to the date in A1. The result is a new date, formatted as a date.
In JavaScript
const d = new Date('2026-01-15');
d.setDate(d.getDate() + 30);
console.log(d.toISOString()); // 2026-02-14
The trick here is that setDate handles month-end rollover automatically. If you add 30 days to January 15, the result is February 14 (31 - 15 + 14 = 30).
In Python
from datetime import date, timedelta
d = date(2026, 1, 15) + timedelta(days=30)
print(d) # 2026-02-14
The timedelta class handles the math. Adding 30 days to January 15 gives February 14.
The first edge case: month-end rollover
When you add months instead of days, the question of "what is one month after January 31?" has two reasonable answers:
- February 28 (or 29 in a leap year): the last day of the next month
- March 3: same day of the next month (Jan 31 + 1 = Feb 31, which does not exist, so we wrap to Mar 3)
Which one is right depends on the convention. Most date libraries have a setting for this. Excel and Google Sheets use the "last day" convention by default (Jan 31 + 1 month = Feb 28). Most programming libraries (Python, JavaScript) use the "wrap" convention (Jan 31 + 1 month = Mar 3).
The Uttir Date Add/Subtract calculator shows both options, with a clear label for which convention is being used.
The second edge case: leap years
February has 29 days in leap years and 28 in regular years. A leap year is any year divisible by 4, except years divisible by 100 that are not also divisible by 400. So:
- 2024 is a leap year (divisible by 4)
- 2025 is not
- 2026 is not
- 2027 is not
- 2028 is a leap year
- 2100 is NOT a leap year (divisible by 100 but not 400)
- 2000 IS a leap year (divisible by 400)
The 100-year exception is rare enough that most calendars ignore it. The 400-year rule (2000 is a leap year) only matters for century boundaries, which is why the rule feels obscure.
For most date arithmetic, the library handles leap years correctly. The Uttir Date Add/Subtract calculator uses the correct rules and shows the result in the user's local timezone.
The third edge case: time zones and DST
When you add 24 hours to a date, you usually get the same date the next day. But during daylight saving time transitions, 24 hours can be 23 or 25 hours of clock time. For most date arithmetic, this does not matter (you are working with calendar dates, not instants). For timestamp arithmetic, it can.
The safe pattern: convert to a date in the relevant timezone, do the arithmetic, convert back. Most libraries handle this automatically if you pass a timezone-aware date. JavaScript's Date object is timezone-naive and uses the local timezone, which can produce surprises in countries with DST.
Calculating age
"How many years between two dates?" is its own calculation, with its own edge cases. The simple version:
age = floor((today - birth_date) / 365.25)
But this is approximate. A more accurate version, used by most age calculators:
- Compute the year difference:
today.year - birth.year - If today's month is before the birth month, subtract 1. If the months are equal but today's day is before the birth day, subtract 1.
The Uttir Age Calculator implements this. The result is the most common "you are N years old" definition, which counts completed years.
Working with weeks
There are two conventions for week numbering:
- Week 1 starts on January 1: the week the year starts, regardless of which weekday. Used in the US (informal).
- Week 1 is the first week with at least 4 days in the new year (ISO 8601) — the week that contains the first Thursday of the year. Used in most of Europe and in business contexts.
If you are computing week numbers, the ISO 8601 convention is the international standard. Excel has a WEEKNUM function with options for both conventions. Programming libraries usually default to ISO 8601 (with an option to use the US convention).
Business days vs calendar days
For most purposes, "days" means calendar days. For business contexts, it often means business days (Monday through Friday, excluding holidays). The two are not the same. 10 business days is roughly 14 calendar days. 10 business days across a long weekend is even more.
For business day arithmetic, you need a library that knows about weekends and holidays. The major ones (Python's workdays, JavaScript's date-fns with the businessDays plugin, Excel's NETWORKDAYS) handle weekends automatically. Holidays require either a holiday calendar (US federal holidays, UK bank holidays, etc.) or a list of dates to skip.
Calculating date differences in a spreadsheet
Three useful formulas:
Days between two dates (absolute value)
=ABS(B1 - A1)
Works regardless of which date is earlier.
Years between two dates (approximate)
=(B1 - A1) / 365.25
Approximate because of leap years. For "how old is this in years", good enough.
Years between two dates (exact)
=DATEDIF(A1, B1, "Y")
DATEDIF is an undocumented but very useful Excel function. The third argument is the unit: "Y" for years, "M" for months, "D" for days. It handles month-end rollover correctly.
Bottom line
Date arithmetic looks simple, but the edge cases (month-end, leap years, time zones, business days) add up. The safe pattern is to use a date library for anything non-trivial, and to use the Uttir Date Add/Subtract calculator for quick one-off calculations. For age calculations, the Age Calculator handles the "completed years" definition correctly. For business day calculations, both tools expose the underlying library functions and document the conventions they use.
Further reading
Reference: Wikipedia — ISO 8601 date notation.
Frequently asked questions
- Why does subtracting local JavaScript Date timestamps sometimes yield a fractional day?
- Daylight Saving Time spring-forward and fall-back days have 23 or 25 hours in local time, so dividing by
86,400,000 msproducesx.958orx.042days. Normalize calendar dates to UTC midnight or use Date Add / Subtract. - How does the Gregorian leap-year rule determine February 29?
- A year is a leap year if it is divisible by 4, except century years (like 1900) which are skipped unless also divisible by 400 (like 2000)—yielding an average year length of 365.2425 days.
- Why do some years have 53 ISO weeks instead of 52?
- Under ISO 8601 week numbering (Monday-start weeks where Week 1 contains the first Thursday), a year has 53 weeks whenever January 1 falls on a Thursday—or on a Wednesday in a leap year.