ThisCalculator

Date and time

Between Dates Calculations: How to Count Days

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.

Between Dates Calculations: How to Count Days

This calculator works out the number of days, weeks, or months between two dates. You enter a start date and an end date, and it returns the exact difference in days, along with the difference broken into years, months, and days. It also shows the total weeks and remaining days, so you can quickly see the span in the units you need.

Formula

The core calculation is simple: Difference = End date − Start date. In JavaScript, dates are stored as milliseconds since January 1, 1970 (the Unix epoch). Subtracting one date from another gives the difference in milliseconds. Dividing by 86,400,000 (the number of milliseconds in one day: 24 × 60 × 60 × 1000) converts that to days.

For the years/months/days breakdown, the calculator uses the calendar difference: it counts whole years between the two dates, then whole months remaining, then the leftover days. This is more accurate for human planning than simply dividing days by 365.25, because months have different lengths.

Worked Example

Using the defaults: Start date = January 1, 2024; End date = December 31, 2024.

  1. Convert both dates to milliseconds: Jan 1, 2024 = 1704067200000 ms; Dec 31, 2024 = 1735689600000 ms.
  2. Subtract: 1735689600000 − 1704067200000 = 31622400000 ms.
  3. Divide by 86,400,000: 31622400000 / 86400000 = 366 days (2024 is a leap year).
  4. Weeks: floor(366 / 7) = 52 weeks, remainder 2 days.
  5. Years/months/days: 1 year (Jan 1 to Jan 1, 2025 would be 366 days, but we stop at Dec 31, so it’s 0 years, 11 months, 30 days if we count from Jan 1 to Dec 1, then 30 more days). The calculator outputs 1.00 years as a decimal, which is 366/365.25 ≈ 1.002.

The result: 366 days, 52 weeks and 2 days, and 1.00 years (decimal).

Why Date Differences Are Trickier Than They Look

Most people think subtracting dates is just counting days on a calendar, but there are several complications:

  • Leap years: February has 29 days every four years (except century years not divisible by 400). This adds an extra day to the year, affecting both day counts and weekly breakdowns.
  • Month lengths: Months vary from 28 to 31 days. A difference of “one monthâ€� can mean 28, 30, or 31 days depending on the months involved.
  • Time zones: If you cross a daylight saving time boundary, a day might be 23 or 25 hours long. For date-only calculations, we ignore time-of-day and use UTC to avoid this.
  • Inclusive vs. exclusive: Some people count the start day (e.g., “3 days from Monday to Thursdayâ€� might be 3 or 4 days depending on whether you include Monday). This calculator gives the exclusive difference (end − start), which is the standard for date math.

How to Read the Result

The Total days is the raw number of 24-hour periods between the two dates. For example, from Jan 1 to Jan 2 is 1 day. The Weeks and days breaks that into whole weeks plus leftover days, useful for planning trips or projects. The Years, months, days gives a calendar-based breakdown, which is what you’d use for age or tenure calculations.

Note that the years output is a decimal (e.g., 1.00 for a full year), not a split into years/months/days. For a precise breakdown, you’d need a more detailed calculator, but this gives a quick estimate.

Common Mistakes and Misconceptions

  • Off-by-one errors: If you want to know how many days until an event, you might need to add 1 if you’re counting today as day 1. This calculator gives the mathematical difference, not the “inclusiveâ€� count.
  • Using 365.25 for all years: That average works for long spans but fails for short ones. A difference of 1 year from March 1, 2023 to March 1, 2024 is 366 days (leap year), not 365.25.
  • Ignoring time zones: If you enter dates with times, the result can be off by a day if the times cross midnight in different zones. Always use date-only inputs for date differences.
  • Assuming months are 30 days: A “6-monthâ€� period from July 31 to January 31 is 184 days, not 180.

When to Use This Calculator

Use this tool for:

  • Calculating the number of days until a deadline or event.
  • Determining the length of a project or vacation.
  • Checking the age of a person or object in days.
  • Planning billing cycles or subscription periods.
  • Converting a date range into weeks for scheduling.

It’s not suitable for legal or financial calculations where precise day-count conventions matter (e.g., 30/360 vs. actual/365). Those require specialized formulas.

Limits of the Formula

This calculator assumes you’re using the Gregorian calendar, which is the standard in most of the world. It doesn’t account for historical calendar changes (like the switch from Julian to Gregorian) or for time-of-day differences. It also treats all days as 24 hours, ignoring daylight saving time. For date-only calculations, that’s fine, but if you need time-of-day precision, you should use a more advanced tool.

Frequently Asked Questions

How do I count days between two dates including the start date?

If you want to include the start date (e.g., “day 1� is the start date), simply add 1 to the result. For example, from Monday to Wednesday is 2 days exclusive, but 3 days inclusive (Monday, Tuesday, Wednesday).

Why does the calculator show 366 days for a year that isn’t a leap year?

It doesn’t. The default example uses 2024, which is a leap year. For a non-leap year like 2023, Jan 1 to Dec 31 is 364 days (or 365 if you include the end date? No, exclusive is 364). Always check the specific dates you entered.

Can I calculate the difference in hours or minutes?

Not with this calculator, as it only accepts dates, not times. For hours/minutes, you’d need a datetime calculator that includes time inputs.

What if my end date is before my start date?

The calculator will return a negative number of days. If you need a positive result, swap the dates or use the absolute value.

How accurate is the years/months/days breakdown?

It’s approximate. The calculator gives a decimal year (total days / 365.25). For a precise breakdown, you’d need a calculator that counts whole months and days, which is more complex due to varying month lengths.

Does this work for dates before 1970?

Yes. The Unix epoch is just a reference point; the calculator handles any date that JavaScript can parse, which is typically from year 0 to 9999.

Related

Formula used
in start | Start date | - | 2024-01-01 | 0
in end | End date | - | 2024-12-31 | 0
out days | Total days | days | (end - start) / 86400000 | 0
out weeks | Weeks and days | - | floor(days / 7) | 0
out years | Years, months, days | - | (end - start) / 31557600000 | 2

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.