How to Calculate Days Between Two Dates (and Add or Subtract Days)
Calculating the days between two dates, or adding days to a date, looks simple but has edge cases. Learn the rules for days, weeks, months, and years, and how to avoid the month-end and leap-year traps.
To calculate days between two dates, subtract the earlier from the later and divide by the number of milliseconds in a day. To add or subtract days, add the corresponding number of milliseconds, or use a date library. The two edge cases to watch: month-end rollover (Jan 31 + 1 month = Feb 28 or Mar 3, depending on convention) and leap years (Feb has 29 days every 4 years, except centuries not divisible by 400). The Uttir Date Arithmetic calculator does this correctly in your browser, with the right conventions for both end-of-month and leap-year behavior.
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.
Common questions
How many days are in a year?
365 in a regular year, 366 in a leap year. The long-term average is 365.2425, which is why the Gregorian calendar has the "divisible by 100 but not 400" rule.
How many weeks are in a year?
52 in most years, 53 in some. The ISO 8601 week-numbering system defines which years have 53 weeks. The rule: a year has 53 weeks if January 1 is a Thursday, or if it is a leap year and January 1 is a Wednesday. Most years are 52 weeks.
How do I add working days in Excel?
Use WORKDAY(start_date, days, [holidays]). The function adds the specified number of working days, skipping weekends and any holidays in the third argument.
How do I find the number of days in a month?
Spreadsheet: =DAY(EOMONTH(A1, 0)). The EOMONTH function returns the last day of the month, and DAY extracts the day-of-month from that. For February 2026 (not a leap year), the result is 28. For February 2024 (a leap year), the result is 29.
What is the Julian day?
A continuous day count used in astronomy and some scientific computing. January 1, 4713 BC is day 0. The Julian day for any modern date can be computed with a formula, but it is rarely needed outside astronomy. For most purposes, the standard date arithmetic is enough.
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.