ThisCalculator

Everyday

Formula Calculate Days Between Dates

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Formula Calculate Days Between Dates

This calculator works out the number of days between two dates. You enter a start date and an end date, and it returns the total days, which you can then use for planning, deadlines, or historical comparisons. The core formula is simple subtraction, but the details of calendar systems and time zones matter.

Formula

The most direct formula for calculating days between two dates is:

Days = (End Date – Start Date) / 86,400,000

Here, each date is represented as a timestamp — the number of milliseconds since January 1, 1970, 00:00:00 UTC (the Unix epoch). Subtracting the two timestamps gives the difference in milliseconds. Dividing by 86,400,000 (the number of milliseconds in one day: 24 hours × 60 minutes × 60 seconds × 1000 ms) converts that difference into whole days.

In spreadsheet software like Excel or Google Sheets, the same idea works with a simpler formula: =B2-A2 (where A2 is the start date and B2 is the end date). Dates are stored as serial numbers, so subtracting them gives the number of days directly.

For manual calculation, especially across months or years, you would break it into steps: count the remaining days in the start month, add the full months in between, then add the days in the end month. That method is error-prone, which is why most people use a calculator or spreadsheet.

Worked Example

Using the default values from the calculator above: start date January 1, 2024, and end date December 31, 2024.

  1. Convert both dates to timestamps (in milliseconds):
    • January 1, 2024, 00:00 UTC → 1704067200000 ms
    • December 31, 2024, 00:00 UTC → 1735689600000 ms
  2. Subtract: 1735689600000 – 1704067200000 = 31622400000 ms
  3. Divide by 86,400,000 ms/day: 31622400000 / 86400000 = 366 days

The result is 366 days because 2024 is a leap year. The calculator shows 366 days, and the weeks approximation is 52.3 weeks.

When to Use This Calculation

You might need the number of days between dates for:

  • Project timelines – how many days until a deadline or milestone.
  • Event planning – counting down to a wedding, vacation, or product launch.
  • Billing or subscription periods – understanding how many days a service covers.
  • Historical analysis – measuring the length of a war, a reign, or a personal milestone.
  • Age calculation – days since birth, though age in years is more common.

The result is a whole number of days; fractional days only appear if you include times of day. For most planning purposes, whole days are what you need.

How to Read the Result

The output “days between” is the number of 24-hour periods that elapse from the start date at midnight to the end date at midnight. If you enter January 1 and January 2, the result is 1 day, not 2. This is the standard convention in date arithmetic: the difference is exclusive of the end date’s start.

If you need to include both the start and end dates (for example, counting the number of days a rental covers from check-in to check-out), add 1 to the result. That is often called an “inclusive” count.

Also note that the result is independent of time zones only if both dates are interpreted at the same time zone. If you enter dates without times, most systems assume midnight in your local time zone, which can shift the result by one day when daylight saving time changes occur.

Common Mistakes and Pitfalls

  • Mixing inclusive and exclusive counts. A hotel stay from June 1 to June 3 is 2 nights (difference), but 3 calendar days (inclusive). Decide which you need.
  • Leap years. February 29 exists in years divisible by 4, except centuries not divisible by 400. 2000 was a leap year; 1900 was not. Forgetting this can throw off manual calculations by a day.
  • Time zone confusion. If you travel across time zones, the “day” boundary shifts. For a fixed location, it’s fine, but for global events, use UTC dates to avoid ambiguity.
  • Excel’s hidden times. If a cell contains a date with a time (like 2024-06-01 14:30), subtracting two such cells gives a fractional day. Format the result as a number, not a date.
  • Rounding too early. In manual calculations, rounding intermediate steps can lead to an off-by-one error. Keep full precision until the final step.

Limits of the Formula

The simple subtraction formula works perfectly for dates within the Gregorian calendar, which is the standard in most of the world. However, it assumes:

  • Both dates are in the same calendar system. If you’re converting from a lunar or Julian calendar, you must first convert to Gregorian.
  • No time component. If you include times, the result is fractional; you’ll need to decide whether to round up, down, or keep the fraction.
  • No historical calendar adjustments. The Gregorian calendar was adopted at different times in different countries (e.g., 1582 in some, 1752 in Britain). For dates before adoption, the formula may not match historical records.

For dates far in the future or past, the timestamp method still works, but floating-point precision can become an issue beyond a few million years, which is rarely relevant.

Alternatives and Related Calculations

If you need more than just days, consider:

  • Business days: Exclude weekends and holidays. This requires a list of holidays, so it’s not a pure formula.
  • Months and years: The number of whole months or years between dates is not a simple division, because months have different lengths. Use a dedicated calculator or spreadsheet function like DATEDIF.
  • Age in years: Usually calculated as the number of full years, which is the floor of the day difference divided by 365.25, but leap years make it more complex.
  • Duration in hours/minutes: Multiply the day difference by 24 for hours, or 1440 for minutes, if you need finer granularity.

Frequently Asked Questions

Does the formula count the start day?

No. The standard subtraction gives the number of full 24-hour periods between the two dates. If you start on June 1 and end on June 2, the result is 1 day. If you want to count both days (inclusive), add 1 to the result.

How do I calculate days including both start and end dates?

Use the formula Days = (End – Start) / 86400000 + 1. For example, from June 1 to June 3, the difference is 2 days, but inclusive it’s 3 days. This is common for rental periods or event durations.

Why does Excel sometimes show a date instead of a number?

Excel stores dates as serial numbers and may format the result as a date. To fix it, select the cell with the formula, go to the Home tab, and change the number format to “Number” or “General.” The underlying value is correct; only the display is wrong.

What about leap years? Does the formula handle them?

Yes, the timestamp method automatically accounts for leap years because each date is mapped to a specific millisecond. February 29, 2024, exists as a valid timestamp, so the difference between March 1 and February 28 includes that extra day.

Is there a difference between calendar days and business days?

Yes. Calendar days include all days of the week. Business days typically exclude weekends and public holidays. The simple formula gives calendar days; to get business days, you must subtract weekends and holidays, which requires a separate calculation.

Can I use this formula for dates before 1970?

Yes. The Unix epoch is just a reference point; timestamps can be negative for dates before 1970. The subtraction still works correctly, as long as your software supports negative timestamps (most do).

Related

Formula used
in start | Start date | - | 2024-01-01 | 0
in end | End date | - | 2024-12-31 | 0
out days | Days between | days | (end - start) / 86400000 | 0
out weeks | Weeks (approx.) | weeks | days / 7 | 1

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.