ThisCalculator

Date and time

Days Between Dates Calculator: How It Works

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.

Days Between Dates Calculator: How It Works

This calculator works out the exact number of days between two dates. You enter a start date and an end date, and it returns the total days, including both endpoints if you choose. It handles leap years and month-length differences automatically, so you get a precise count without manual calendar math.

Formula

The core formula is simple: Days = (End Date − Start Date) ÷ 86,400,000 (since 1 day = 24 × 60 × 60 × 1000 milliseconds). If you choose “Include both,� we add 1 to count the start day as well. The calculator internally converts both dates to timestamps (milliseconds since January 1, 1970), subtracts them, and divides by the number of milliseconds in a day. Leap years are handled automatically because the calendar system already accounts for February 29 when it exists.

Variables: Start Date and End Date are calendar dates in YYYY-MM-DD format. The result is a whole number of days, with an optional fractional weeks output.

Worked Example

Using the defaults: Start = 2025-01-01, End = 2025-12-31, and “Include both� selected.

  1. Convert 2025-01-01 to timestamp: 1735689600000 ms.
  2. Convert 2025-12-31 to timestamp: 1767225600000 ms.
  3. Subtract: 1767225600000 − 1735689600000 = 31536000000 ms.
  4. Divide by 86,400,000: 31536000000 ÷ 86400000 = 365 days.
  5. Add 1 (include both) → 366 days.

The calculator shows 366 days. That’s correct because 2025 is not a leap year, but counting both January 1 and December 31 gives 366 distinct days.

When to Use This Calculator

This tool is useful for any situation where you need a precise day count:

  • Counting down to a birthday, anniversary, or vacation.
  • Calculating how long a project has been running or how many days remain until a deadline.
  • Working out the length of a rental period, subscription, or warranty.
  • Determining age in days (for fun or for tracking infant milestones).
  • Verifying billing cycles or interest accrual periods (though always confirm with your provider).

The result is exact for the calendar, but it does not account for time-of-day. If you enter dates without times, it treats each as midnight, which is standard for date-only calculations.

How to Read the Result

The main number is the count of days between the two dates. If you select “Exclude end,� the result is the number of full 24-hour periods between the dates. If you select “Include both,� it counts the start date as day 1, which is common when counting “days until� an event (e.g., “10 days until Christmas� often means 10 sleeps). The weeks output is an approximation (days ÷ 7) with one decimal, useful for quick comparisons.

Note that the calculator does not subtract weekends or holidays. It gives the raw calendar difference. For business days, you’d need a separate tool that knows which days are working days.

Common Mistakes and Pitfalls

One frequent error is mixing up the order of dates. If the end date is earlier than the start date, the result will be negative. The calculator will show a negative number, which is mathematically correct but may surprise you. Always double-check that you’ve entered the earlier date first.

Another mistake is assuming the result includes both endpoints when it doesn’t. For example, from Monday to Friday is 4 days if you exclude Friday, but 5 days if you count both. Always clarify which convention you need.

Leap years are handled correctly, but be aware that February 29 only exists in leap years. If you enter February 29, 2025, the calculator will reject it because that date doesn’t exist. Use February 28 or March 1 instead.

Limitations and Edge Cases

This calculator works for dates in the Gregorian calendar, which is the standard civil calendar worldwide. It does not support historical calendar changes (like the Julian calendar) or time zones. If you need time-zone-specific day counts (e.g., “how many days until New Year in Tokyo�), the result may differ by one day depending on your location. For most purposes, the date-only approach is sufficient.

The calculator also ignores daylight saving time changes. Since we work with dates at midnight, a day with a DST shift is still treated as 24 hours. This is fine for date arithmetic but could be off by an hour for time-specific calculations.

Alternatives and Related Calculations

If you need more than just days, consider these related calculations:

  • Business days: Count only weekdays, optionally excluding holidays. This requires a holiday calendar.
  • Duration in years, months, days: Instead of a flat day count, you might want “2 years, 3 months, 4 days.â€� That’s a different calculation that accounts for month lengths.
  • Time difference: If you have times of day, you may want hours, minutes, and seconds between two moments.
  • Age calculator: Computes a person’s age in years, months, and days from birthdate to today.

For most quick questions, this day-count calculator is the simplest and most direct tool.

Frequently Asked Questions

How do I count days including both the start and end date?

Select “Include both� in the calculator. This adds 1 to the raw difference. For example, from January 1 to January 2 is 1 day by difference, but 2 days if you count both dates. This is common when counting “days until� an event.

Why does the calculator show a negative number?

You entered the end date earlier than the start date. The calculator subtracts start from end, so if the end is earlier, the result is negative. Swap the dates to get a positive number.

Does this calculator handle leap years?

Yes. The underlying date system includes leap years, so February 29 is counted correctly. For example, from February 28, 2024 to March 1, 2024 is 2 days (including both), because 2024 is a leap year.

What if I need to count business days only?

This calculator counts all calendar days. For business days, you need a tool that excludes weekends and holidays. You can approximate by multiplying the day count by 5/7, but that’s not exact because holidays vary by country and region.

Can I calculate days between dates in different years?

Yes, the calculator works for any valid Gregorian calendar dates, from year 1 to 9999. Just enter the full year, month, and day in YYYY-MM-DD format.

Why is the result one day off from what I expected?

Check whether you’re counting the end date. If you expect “5 days� from Monday to Friday, you’re likely including both Monday and Friday. If you exclude the end date, you get 4 days. Also verify that you didn’t accidentally enter the wrong year or month.

Related

Formula used
in start | Start date | - | 2025-01-01 | -
in end | End date | - | 2025-12-31 | -
sel inclusive | Count method | Exclude end=0, Include both=1
out days | Days between | days | (end - start) / 86400000 + inclusive | 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.