How to Calculate Days Between Dates: A Complete Guide
How many days until your lease expires? How long has it been since your last dental appointment? How many business days are left in this quarter? These questions sound simple, but date arithmetic is deceptively tricky. Months have different lengths, leap years add a day every four years (with exceptions), and if you need business days, weekends and public holidays enter the picture.
This guide explains how date calculations actually work, the traps to avoid, and how to handle the most common real-world scenarios — from pregnancy due dates to contract expirations.
Why Date Calculation Is Harder Than It Looks
Human calendars are not regular. The Gregorian calendar, which most of the world uses today, has:
- Months of unequal length: 28, 29, 30, or 31 days
- A leap year every 4 years — except century years, which are only leap years if divisible by 400 (so 2000 was a leap year, 1900 was not)
- No year zero — the calendar goes from 1 BC directly to 1 AD
This means you cannot simply subtract the numeric date values and get a correct answer. February 28, 2024 to March 1, 2024 is 2 days (2024 was a leap year), but February 28, 2023 to March 1, 2023 is only 1 day.
How the Math Actually Works: Julian Day Numbers
Professional date calculation libraries use a concept called the Julian Day Number (JDN) — a continuous count of days from a fixed starting point (noon on January 1, 4713 BC in the proleptic Julian calendar, if you want to be precise). Every date in history can be converted to a single integer, and the difference between two dates is simply the difference between their JDNs.
The conversion formula from a Gregorian date (year Y, month M, day D) to JDN is:
a = (14 - M) / 12
y = Y + 4800 - a
m = M + 12 * a - 3
JDN = D + (153*m + 2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
In practice, you never need to implement this yourself — every programming language and spreadsheet provides date functions that handle this internally. But understanding the concept explains why date math always routes through a day-count intermediary.
Calculating Calendar Days Between Two Dates
The simplest case: how many days from Date A to Date B, counting all calendar days?
In Python:
from datetime import date
date1 = date(2026, 1, 1)
date2 = date(2026, 12, 31)
delta = date2 - date1
print(delta.days) # 364
In JavaScript:
const date1 = new Date('2026-01-01');
const date2 = new Date('2026-12-31');
const diffMs = date2 - date1; // milliseconds
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
console.log(diffDays); // 364
Or just use our date difference calculator — enter two dates and get the result instantly, no code required.
Calculating Business Days (Excluding Weekends)
Business day calculation is significantly more complex because you need to exclude Saturdays and Sundays — and optionally, public holidays. The basic approach:
- Count total calendar days
- Subtract the number of Saturdays and Sundays in that range
- Optionally subtract public holidays that fall on weekdays
The tricky part is that the number of weekends in a given span depends on which day of the week the start date falls on. A 7-day period starting on Monday contains 2 weekend days; starting on Saturday, it contains 2 weekend days but a different pair. Our work day calculator handles this correctly for any date range.
Time Zones and the Hidden Pitfall
Date calculations become dangerous when time zones enter the picture. Consider this JavaScript code:
const date1 = new Date('2026-03-07'); // interpreted as UTC midnight
const date2 = new Date('2026-03-08');
const diffDays = (date2 - date1) / (1000 * 60 * 60 * 24);
// In UTC: 1 day. But if your local timezone is UTC-5,
// new Date('2026-03-07') becomes 2026-03-06T19:00:00 local time
This is why JavaScript date manipulation is notoriously error-prone. Libraries like date-fns and Luxon provide timezone-aware alternatives. When you use our date difference calculator, dates are parsed and compared in a timezone-consistent manner to avoid this class of errors.
The practical rule: when calculating days between dates that span daylight saving time transitions, add or subtract 12 hours before dividing by 24 to avoid off-by-one errors caused by the 1-hour DST shift.
Common Real-World Date Calculations
How Many Days Until a Deadline?
Enter today's date and your deadline into the date difference calculator. It will tell you the exact number of days remaining, including whether the deadline falls on a weekend.
How Old Am I in Days?
Enter your date of birth as the start date and today as the end date. Most people are surprised to discover they are over 10,000 days old by their late 20s (10,000 days is approximately 27 years and 4 months). Our age calculator computes your exact age in years, months, and days simultaneously.
Pregnancy Due Date Calculation
A standard pregnancy lasts 280 days (40 weeks) from the first day of the last menstrual period. Enter the start date in our date calculator and add 280 days to find the estimated due date.
Lease or Contract Expiry
If your lease is 12 months from March 15, 2026, the end date is March 15, 2027 (calendar months, not days). But if it's 365 days, the end date is March 15, 2027 — same result in a non-leap year. In a leap year, 365 days from March 15 would be March 14 the following year. Lease agreements should always specify calendar months or an explicit end date to avoid ambiguity.
Loan Maturity Date
A 30-year mortgage starting April 1, 2026 matures on April 1, 2056. Simple calendar month addition is correct here. But a 90-day promissory note needs exact day counting: starting April 1, 2026, 90 days later is June 30, 2026.
Days Since a Historical Event
Apollo 11 landed on the Moon on July 20, 1969. As of March 7, 2026, that is approximately 20,683 days ago. Most date calculators handle historical dates back to at least January 1, 1900.
Date Differences in Spreadsheets
If you prefer spreadsheets:
- Excel / Google Sheets:
=DAYS(end_date, start_date)or simply=end_date - start_date(format the result as a number) - Business days in Google Sheets:
=NETWORKDAYS(start_date, end_date)— includes both endpoints;=NETWORKDAYS(start_date, end_date) - 1to exclude the start date
How Our Date Difference Calculator Handles All This
Our date difference calculator runs entirely in your browser. It handles:
- Leap years automatically
- Results in days, weeks, months, and years simultaneously
- Historical dates back centuries
- Future dates for planning ahead
No sign-up required, no data sent to any server. Just enter two dates and get the answer.
Frequently Asked Questions
Does the calculation include both the start and end date?
This depends on context. "Days between" typically counts the gap — from January 1 to January 3 is 2 days. "Days inclusive" or "days from ... through ..." counts both endpoints — January 1 through January 3 is 3 days. Our calculator computes the gap (exclusive of the start date), which is the standard mathematical interpretation. In legal and business contexts, always clarify whether the start and end dates are included.
How are leap years handled in date calculations?
A year is a leap year if it is divisible by 4, except for century years, which must be divisible by 400. So 2000 was a leap year, but 1900 and 2100 are not. Modern date libraries handle this automatically. When you cross a leap day (February 29) in your date range, the calculation correctly adds that extra day.
How do I calculate working days between two dates?
Use our work day calculator, which automatically excludes Saturdays and Sundays. For public holidays, you'll need to manually subtract the number of public holidays that fall on weekdays within your date range, as these vary by country and region.
Why does my spreadsheet show a wrong date when I subtract dates?
If you subtract two dates in Excel or Google Sheets and see a result like "1/2/1900" instead of a number, the result cell is formatted as a date rather than a number. Select the cell and format it as "Number" to see the correct day count.
How many days are in a year for calculation purposes?
A calendar year has 365 days (or 366 in a leap year). However, financial calculations often use a "day count convention" — 365, 360, or 365/360 depending on the instrument. Treasury bonds use Actual/Actual (actual calendar days), while many corporate bonds use 30/360 (each month assumed to have 30 days, each year 360). For everyday date calculations, use actual calendar days.