Date Difference Calculator
Find the number of days, weeks, months between two dates.
About the Date Difference Calculator
The Date Difference Calculator measures the elapsed time between two calendar dates. Behind the simple ‘subtract the dates’ formula lies a surprisingly complex problem: months have 28 to 31 days, leap years add an extra day every four years (except centuries, except quadricenturies), and the Gregorian calendar reform of 1582 dropped 10 days to resynchronize with the solar year. The browser’s Date object handles all of these complications via the proleptic Gregorian calendar defined in ISO 8601.
The basic calculation is Math.floor((end - start) / 86400000) — the difference in milliseconds divided by the number of milliseconds in one day (86,400,000). The result is the number of full days between the two dates, exclusive of the end date. If you need inclusive counting (where both start and end days count as 1), add 1.
Approximate conversions to larger units use standardized averages: 1 week = 7 days (exact), 1 month ≈ 30.44 days (the average across 4 years including leap), 1 year ≈ 365.24 days (the Gregorian year length). These approximations are correct within ±1 day over periods of less than a year and within ±5 days over periods up to a decade.
How It Works
The calculator subtracts two Date objects via JavaScript’s type coercion, which converts each to its Unix timestamp (milliseconds since 1970-01-01 UTC). The difference is in milliseconds; dividing by 86400000 (the number of ms in one day: 24 × 60 × 60 × 1000) yields the day count. Math.floor truncates fractional days.
Daylight Saving Time transitions would normally cause a 23- or 25-hour day, breaking the simple division. To avoid this, both dates are constructed at midnight local time using the T00:00:00 suffix. The browser interprets the date in the user’s local timezone, and DST shifts occur at 2 AM (in most jurisdictions), well after midnight — so the day count remains accurate.
For weekend-skipping mode, the algorithm walks from start to end one day at a time using Date.setDate(date.getDate() + 1). Each iteration checks date.getDay() (0 = Sunday, 6 = Saturday) and counts only weekdays (1–5). This is O(N) where N is the day count — fast for ranges up to several years, slow for ranges over a century. For longer ranges, a closed-form formula (counting full weeks and adding remainder) is more efficient.
The inclusive-counting option adds 1 to the day count, matching conventions used in hotel-night calculations and some legal contexts. ‘Nights from January 1 to January 3’ is 2 nights exclusive, or 3 days inclusive — both interpretations are valid depending on context.
Worked Examples
From 2025-01-01 to 2025-12-31 (one calendar year minus one day): 364 days exclusive, 365 days inclusive. The full calendar year 2025 (January 1 to December 31) is 364 days exclusive, but inclusive counting gives 365 — the same as the year length, because 2025 is not a leap year.
From 2024-01-01 to 2024-12-31 (leap year): 365 days exclusive, 366 inclusive. The extra day (February 29) makes 2024 a leap year.
From 2024-01-01 to 2025-01-01 (exactly one year including leap day): 366 days. Approximate month count: 366 / 30.44 ≈ 12.02 months. Approximate year count: 366 / 365.24 ≈ 1.002 years — the slight overage accounts for the leap day.
From 2025-03-03 to 2025-03-07 (one work week): 4 days exclusive (Monday through Thursday, with Friday as the end). Inclusive mode gives 5 days (Monday through Friday). With weekend-skipping enabled: 4 weekdays exclusive (Mon-Thu) or 5 weekdays inclusive (Mon-Fri).
When to Use This Tool
- Project planning — count the days between project start and deadline to scope the work.
- Legal deadlines — many jurisdictions count ‘X days from service’ in a specific way (inclusive or exclusive of the service date).
- Travel planning — count nights between arrival and departure for hotel booking (inclusive counting).
- Investment horizon — the number of days between purchase and sale determines short-term vs. long-term capital gains treatment in the US (1-year threshold).
- Subscription tracking — days remaining until renewal, to plan cancellations before auto-renew.
- Pregnancy dating — obstetricians count from the last menstrual period, with full-term pregnancy being 280 days (40 weeks).
- Aging experiments — number of days since a specific event for personal milestones (‘1000 days since...’).
Limitations & Disclaimer
The calculator uses the proleptic Gregorian calendar defined in ISO 8601 — dates before 1582 (when the Gregorian calendar was introduced) are treated as if it applied retroactively, which is historically inaccurate for events recorded under the Julian calendar. DST transitions are handled by constructing both dates at midnight local time; for time-of-day differences across DST boundaries, a time-aware calculator is required. The ‘approximate months’ output uses an average of 30.44 days/month and may be off by ±1 day for short periods; for exact month counts use the Age Calculator. Weekend-skipping mode does not exclude public holidays — use the Working Days Calculator for that. See our disclaimer for full terms.
Frequently Asked Questions
Does the calculator account for leap years?
Yes. The browser’s <code>Date</code> object implements the Gregorian leap-year rule: divisible by 4, except centuries, except quadricenturies. So 2000 was a leap year, 1900 was not, 2024 was, 2025 is not. The day count between February 28 and March 1 is 1 day in non-leap years and 2 days in leap years (because February 29 is in between).
Why is the ‘approximate months’ not exact?
Because months have variable lengths (28 to 31 days), there is no exact conversion from days to months. The calculator uses <code>30.436875 days per month</code>, the average across a 4-year Gregorian cycle (365.25 × 4 / 48). For exact month counts, use the ‘Age Calculator’ with a custom target date — it computes year/month/day breakdowns directly.
What is the difference between inclusive and exclusive counting?
Exclusive counting is the number of full days between two dates (the standard for elapsed-time calculations). Inclusive counting adds 1, treating both the start and end dates as full days. Hotel-night calculations use inclusive counting (3 nights from Jan 1 to Jan 3 = 3 nights). Legal deadlines vary by jurisdiction — check the local rules of civil procedure.
Does the calculator handle Daylight Saving Time?
Yes — both dates are constructed at midnight local time, which avoids DST transitions (they occur at 2 AM in most jurisdictions). If you need exact time-of-day differences across a DST transition, use a calculator that accepts time of day and stores timezone offset.
Can I count only weekdays?
Yes — check ‘Skip Weekends’ to count only Monday-Friday days. The calculator walks day-by-day and excludes Saturdays and Sundays. Note that public holidays are NOT excluded — for working-day calculations excluding holidays, use the dedicated <a href='/tools/working-days-calculator.php'>Working Days Calculator</a>.
What is the maximum range I can calculate?
Approximately ±271,800 years from the Unix epoch (1970-01-01), limited by the 64-bit floating-point precision of the JavaScript <code>Date</code> object. For dates outside this range (ancient history, far-future scenarios), use a dedicated astronomical calculator such as <a href='https://stellafane.org/misc/bcdates.html'>Stellafane’s BC/AD calculator</a>.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team