How to Calculate Days Between Two Dates: Complete Date Math Guide
Learn how to calculate days between two dates, add or subtract days, and handle leap years. Covers manual methods, business day counting, the Gregorian calendar, and programming examples.
Introduction
Date calculations are one of those everyday tasks that seem simple until you actually try to do them. How many days until your vacation? When does a 90-day warranty expire? How many business days between signing a contract and the delivery deadline?
The tricky part is that our calendar is not a clean, uniform system. Months have different lengths (28, 29, 30, or 31 days), leap years add an extra day every four years (with exceptions), and business day counts skip weekends and holidays. A mistake of even one day can mean a missed deadline, a miscalculated payment, or an incorrect age.
This guide walks through everything you need to know about date math: how to calculate the number of days between two dates by hand, how to add and subtract dates, how leap years work, the difference between business days and calendar days, a brief history of the Gregorian calendar, common date calculations people search for, and how to handle dates in programming.
Try our free Date Calculator to find days between dates, add or subtract days, and get instant results.
How to Calculate Days Between Two Dates
There are several methods for finding the number of days between two dates. The simplest is to count day by day, but for dates far apart, more systematic approaches save time and reduce errors.
Method 1: Month-by-Month Counting
This is the most intuitive manual approach:
- Count the remaining days in the start month. Subtract the start day from the total days in that month.
- Add the full days for each intermediate month. Sum up the total days in every month between the start and end months.
- Add the day number of the end date.
Example: March 15 to June 10
- Remaining days in March: 31 - 15 = 16
- Full months: April (30) + May (31) = 61
- Days in June: 10
- Total: 16 + 61 + 10 = 87 days
Method 2: Day-of-Year Numbers
Each date can be expressed as a day-of-year number (1 through 365 or 366). January 1 is day 1, February 1 is day 32, and so on. To find days between two dates in the same year, simply subtract the day-of-year numbers.
Day-of-year reference (non-leap year):
| Month | First Day # | Days in Month |
|---|---|---|
| January | 1 | 31 |
| February | 32 | 28 |
| March | 60 | 31 |
| April | 91 | 30 |
| May | 121 | 31 |
| June | 152 | 30 |
| July | 182 | 31 |
| August | 213 | 31 |
| September | 244 | 30 |
| October | 274 | 31 |
| November | 305 | 30 |
| December | 335 | 31 |
Example: January 20 to September 5 (non-leap year)
- January 20 = day 20
- September 5 = day 244 + 5 - 1 = day 248
- Difference: 248 - 20 = 228 days
Method 3: Across Multiple Years
For dates spanning different years:
- Count the remaining days from the start date to December 31 of the start year.
- Add 365 for each complete common year or 366 for each complete leap year between them.
- Add the day-of-year number for the end date.
Example: November 10, 2024 to March 5, 2026
- Days remaining in 2024: Nov has 30 days, so 20 remaining + 31 (Dec) = 51 days
- All of 2025 (common year): 365 days
- Days in 2026 through March 5: 31 (Jan) + 28 (Feb) + 5 (Mar) = 64 days
- Total: 51 + 365 + 64 = 480 days
Adding and Subtracting Dates
Adding days to a date or subtracting days from a date follows a similar logic to the methods above, but in reverse.
Adding Days to a Date
To add N days to a given date:
- Add N to the current day number.
- If the result exceeds the days in the current month, subtract the remaining days in that month and move to the next month.
- Repeat until all days are accounted for.
Example: Add 45 days to January 20
- Remaining days in January: 31 - 20 = 11 days. After January: 45 - 11 = 34 days remaining.
- All of February (non-leap): 28 days. After February: 34 - 28 = 6 days remaining.
- March 6.
- Result: March 6
Subtracting Days from a Date
To subtract N days from a given date:
- Subtract N from the current day number.
- If the result is zero or negative, move to the previous month and add that month's total days.
- Repeat until the remaining subtraction is zero.
Example: Subtract 50 days from April 15
- Subtract from April: 15 days. Remaining: 50 - 15 = 35. End of March.
- Subtract from March: 31 days. Remaining: 35 - 31 = 4. End of February.
- Subtract from February (non-leap): 28 days. But we only need 4 more days.
- February 28 - 4 = February 24.
- Result: February 24
Adding Months
Adding months is less straightforward because months have different lengths. The standard approach:
- Add the specified number of months to the month component.
- If the resulting day exceeds the new month's length, clamp to the last day.
Example: January 31 + 1 month = February 28 (or February 29 in a leap year). The day is clamped because February does not have 31 days.
Leap Year Rules and Their Impact on Calculations
Leap years are the single biggest source of errors in manual date calculations. Understanding the rules is essential.
The Three Rules
A year is a leap year if and only if:
- It is divisible by 4 (2024, 2028, 2032 are leap years)
- EXCEPT if it is divisible by 100 (1900, 2100, 2200 are NOT leap years)
- EXCEPT if it is also divisible by 400 (2000, 2400 are leap years)
Why These Rules Exist
The Earth takes approximately 365.2422 days to orbit the Sun. A calendar with exactly 365 days drifts by about 1 day every 4 years. The leap year system corrects this:
- Adding 1 day every 4 years gives 365.25 days/year (slightly too long)
- Skipping century years gives 365.24 days/year (slightly too short)
- Adding back every 400th year gives 365.2425 days/year (very close to 365.2422)
Impact on Date Calculations
When your date range spans February in a potential leap year, you must check whether that year is a leap year:
- January 1 to December 31: 364 days in a common year, 365 in a leap year
- February 28 to March 1: 1 day in a common year, 2 days in a leap year
- Crossing multiple years: Each leap year in the range adds one extra day
A common mistake is assuming every year divisible by 4 is a leap year. The year 1900 was not a leap year, and 2100 will not be either.
Business Days vs Calendar Days
In legal, financial, and business contexts, the distinction between business days and calendar days is critical.
What Is a Business Day?
A business day is any weekday (Monday through Friday) that is not a public holiday. The concept excludes:
- Saturdays and Sundays (weekends)
- Public holidays (which vary by country and sometimes by state/region)
Counting Business Days
To count business days between two dates:
- Count the total calendar days between the dates.
- Calculate the number of complete weeks (divide by 7) and multiply by 5 for the business days in those weeks.
- Count the weekdays in any remaining partial week.
- Subtract any public holidays that fall on weekdays within the range.
Example: Monday, March 2 to Friday, March 13
- Total calendar days: 11
- Complete weeks: 1 (7 days = 5 business days)
- Remaining 4 days: Tuesday through Friday = 4 business days
- Total business days: 5 + 4 = 9 (assuming no holidays)
Business Days in a Year
A standard year has 52 weeks and 1 day, giving 260 weekdays. However:
- The extra 1 day (or 2 in a leap year) may or may not be a weekday
- The US has 11 federal holidays, bringing the typical count to about 249-251 business days
- Other countries have different holiday counts
Common Business Day Deadlines
Many legal and financial processes use business day counts:
- 3 business days: Typical stock trade settlement (T+2 is now standard, but T+3 was used historically)
- 5 business days: Common deadline for responses in business correspondence
- 10 business days: Standard processing time for many government applications
- 30 business days: Common in contract terms and regulatory filings
The Gregorian Calendar
Understanding why our calendar works the way it does helps explain the quirks of date calculations.
The Julian Calendar
In 46 BC, Julius Caesar introduced the Julian calendar, replacing the chaotic Roman calendar. The Julian calendar had 365 days with a leap year every 4 years, giving an average year of 365.25 days. This was a significant improvement but slightly overestimated the solar year by about 11 minutes and 14 seconds per year.
The Problem
Over centuries, this small error accumulated. By the 1500s, the calendar had drifted about 10 days from the astronomical seasons. The spring equinox, which should fall around March 20-21, was occurring around March 11. This mattered enormously for the Catholic Church because Easter's date depends on the spring equinox.
Gregory XIII's Correction
In 1582, Pope Gregory XIII introduced the Gregorian calendar with two key changes:
- Dropped 10 days: October 4, 1582 was followed by October 15, 1582, realigning the calendar with the seasons.
- Modified the leap year rule: Century years would no longer be leap years unless divisible by 400. This changed the average year from 365.25 to 365.2425 days, much closer to the actual 365.2422.
Adoption Timeline
Not all countries adopted the Gregorian calendar at the same time:
- 1582: Catholic countries (Italy, Spain, Portugal, Poland)
- 1752: Britain and its colonies (including what became the United States) skipped 11 days
- 1918: Russia adopted it after the Russian Revolution
- 1923: Greece was one of the last European countries to switch
This staggered adoption means historical date calculations across countries can be complex. A date in "old style" (Julian) and "new style" (Gregorian) may differ by 10-13 days depending on the century.
The Curious Case of Missing Days
When Britain adopted the Gregorian calendar in 1752, September 2 was followed by September 14 — eleven days simply vanished from the calendar. According to popular legend, people rioted in the streets demanding "Give us our eleven days!" Whether the riots actually happened is debated by historians, but the calendar change did create real confusion: when were rents due? How old were people legally? When did contracts expire?
Similar confusion arose in Russia, where the October Revolution of 1917 actually took place in November by the Gregorian calendar. The 13-day difference between the Julian and Gregorian calendars by that point meant that October 25 (Julian) was November 7 (Gregorian).
Date Math in Real-World Contexts
Legal and Contractual Deadlines
Legal systems use specific rules for counting days in deadlines:
- "Within 30 days" typically means 30 calendar days from the day after the triggering event. If a contract is signed on March 1, "within 30 days" usually means by March 31.
- "10 business days" excludes weekends and often federal holidays. The exact holidays that count depend on the jurisdiction.
- Filing deadlines that fall on a weekend or holiday are usually extended to the next business day in most US courts.
- Statute of limitations calculations count from the date the cause of action accrues, and even a one-day error can mean the difference between a valid and an invalid claim.
Medical and Health Calculations
Date calculations are critical in medicine:
- Pregnancy due dates are calculated as 280 days (40 weeks) from the first day of the last menstrual period, using Naegele's rule (subtract 3 months and add 7 days)
- Medication schedules often use "every X days" or "every X hours" timing that must be calculated precisely
- Quarantine periods are counted in calendar days from the date of exposure
- Vaccination schedules specify minimum intervals between doses that must be met for effectiveness
Financial Calculations
Banks and financial institutions use different day count conventions:
- Actual/365: Uses the actual number of days divided by 365 (used for US Treasury bonds)
- Actual/360: Uses the actual number of days divided by 360 (used for money market instruments and many loans)
- 30/360: Assumes every month has 30 days and the year has 360 days (used for corporate bonds and some mortgages)
These conventions affect interest calculations. A loan using Actual/360 accrues slightly more interest than one using Actual/365 because dividing by 360 produces a larger daily rate.
Common Date Calculations People Search For
Here are some of the most frequently searched date calculations with quick answers:
How Many Days Until...
| Event | Typical Calculation |
|---|---|
| 30 days from today | Add 30 to today's date |
| 60 days from today | Add 60 to today's date |
| 90 days from today | Add 90 (roughly 3 months) |
| 180 days from today | Add 180 (roughly 6 months) |
| 1 year from today | Add 365 (or 366 if crossing a leap year Feb 29) |
Duration of Common Periods
| Period | Days |
|---|---|
| 1 week | 7 |
| 2 weeks | 14 |
| 1 month | 28-31 (varies) |
| 1 quarter | 90-92 |
| 1 semester | ~120 |
| 6 months | 181-184 |
| 1 year | 365 or 366 |
| 1 decade | 3,652 or 3,653 |
Age Calculation
To calculate someone's exact age:
- Subtract the birth year from the current year.
- If the current month and day are before the birth month and day, subtract 1 (their birthday hasn't happened yet this year).
- For months and days, calculate the remaining difference.
Programming Date Calculations
Modern programming languages have robust date libraries that handle all the complexity of calendars, leap years, and time zones.
JavaScript
Python
Excel and Google Sheets
Spreadsheets make date calculations accessible without programming:
=DATEDIF(A1, B1, "D") -- Days between two dates
=DATEDIF(A1, B1, "M") -- Months between two dates
=DATEDIF(A1, B1, "Y") -- Years between two dates
=A1 + 90 -- Add 90 days to a date
=NETWORKDAYS(A1, B1) -- Business days between dates
=NETWORKDAYS(A1, B1, holidays) -- Business days minus holidays
=EDATE(A1, 3) -- Add 3 months to a date
=EOMONTH(A1, 0) -- Last day of the month
The NETWORKDAYS function is particularly useful because it automatically excludes weekends, and you can pass an optional range of holiday dates to exclude those as well.
Key Pitfalls in Programming
-
Time zones: Creating a Date object in JavaScript uses the local time zone by default. Two dates that appear to be 1 day apart could be 0 or 2 days apart depending on time zone and daylight saving transitions.
-
Daylight Saving Time: When clocks spring forward, a day might be 23 hours. When they fall back, a day might be 25 hours. Using millisecond differences can produce off-by-one errors near DST transitions.
-
Month indexing: JavaScript months are 0-indexed (January = 0), while Python months are 1-indexed (January = 1). This is a frequent source of bugs.
-
Mutability: JavaScript's
Date.setDate()modifies the original object. Always create a new Date if you need to preserve the original. -
End-of-month edge cases: Adding one month to January 31 in JavaScript gives March 3 (because February 31 overflows). Different languages handle this differently — some clamp to the last day of the month, others overflow into the next month.
-
Year 2038 problem: Systems that store dates as 32-bit Unix timestamps will overflow on January 19, 2038. Most modern systems use 64-bit timestamps, which last until the year 292,277,026,596.
Frequently Asked Questions
How do you count days between two dates including the start date?
Standard date difference calculations exclude the start date and include the end date (for example, January 1 to January 3 = 2 days). If you need to include both the start and end dates, simply add 1 to the result. This is sometimes called "inclusive counting" and is used in some legal and medical contexts.
Why do some months have 30 days and others 31?
The pattern traces back to the Roman calendar. July (named after Julius Caesar) and August (named after Augustus Caesar) both have 31 days — legend says Augustus refused to have fewer days than Julius. The remaining months alternate between 30 and 31, except February, which was the last month in the original Roman calendar and got the shortest allocation.
How accurate is the Gregorian calendar?
The Gregorian calendar has an average year length of 365.2425 days, while the actual solar year is about 365.2422 days. The difference is 0.0003 days per year, meaning the calendar drifts by 1 day every 3,236 years. It will be thousands of years before any correction is needed.
What is a Julian Day Number?
A Julian Day Number (JDN) is a continuous count of days since the beginning of the Julian Period on January 1, 4713 BC. Astronomers use it to avoid the complexities of different calendar systems. For example, January 1, 2026 is JDN 2,461,042. To find days between two dates, subtract their Julian Day Numbers.
How do you handle date calculations across different time zones?
For date-only calculations (without time), use UTC dates to avoid time zone complications. If you need time-aware calculations, convert both dates to the same time zone first, then compute the difference. Most programming languages provide libraries for time zone conversion.
What is ISO 8601 and why does it matter for dates?
ISO 8601 is the international standard for representing dates and times. The format is YYYY-MM-DD (e.g., 2026-03-19). Using this format eliminates ambiguity between DD/MM/YYYY (common in Europe) and MM/DD/YYYY (common in the US). Most programming languages and databases support ISO 8601 natively.
How do you calculate the number of weekdays between two dates without a calculator?
Count the number of complete weeks between the dates and multiply by 5. Then count the remaining weekdays in any partial week at the start or end. For example, from Wednesday to the following Tuesday is 1 complete week (5 business days) plus the remaining days. Subtract any holidays that fall on weekdays.
Can you calculate dates before the Gregorian calendar was adopted?
Yes, but with caveats. Dates before October 15, 1582 (or later, depending on the country) are typically expressed in the Julian calendar. When calculating across the adoption boundary, you must account for the 10-13 days that were skipped. Many date calculators use the "proleptic Gregorian calendar," which extends Gregorian rules backward in time even before the calendar existed.