Days Between Dates: Calculate & Count Months
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.
This calculator works out the exact number of days, months, and years between two dates. You enter a start date and an end date, and it returns the total days, the number of full months, and the remaining days, plus the total months as a decimal. The result is based on the calendar, so leap years and different month lengths are handled automatically.
Formula
The core calculation is simple: Days = End Date − Start Date, where each date is converted to a timestamp (milliseconds since January 1, 1970). The difference in milliseconds is divided by 86,400,000 (the number of milliseconds in one day) and rounded down to give whole days.
For months, there is no single “correct� formula because months vary from 28 to 31 days. This calculator uses the average month length of 30.44 days (365.25 ÷ 12) to convert days into a decimal number of months. For full calendar months, it counts how many month boundaries you cross, then subtracts any partial month at the start or end.
Variables:
- d1 – start date (YYYY-MM-DD)
- d2 – end date (YYYY-MM-DD)
- Days – total elapsed days, always a whole number
- Months – days ÷ 30.44, rounded to one decimal
- Years – days ÷ 365.25, rounded to two decimals
Worked Example
Using the default values: start date 2024-01-15, end date 2025-03-20.
- Convert both dates to timestamps: 2024-01-15 → 1705276800000 ms; 2025-03-20 → 1742428800000 ms.
- Subtract: 1742428800000 − 1705276800000 = 37152000000 ms.
- Divide by 86,400,000 ms/day: 37152000000 ÷ 86400000 = 430 days exactly.
- Months (decimal): 430 ÷ 30.44 = 14.126… → 14.1 months.
- Years (decimal): 430 ÷ 365.25 = 1.177… → 1.18 years.
So the calculator shows: 430 days, 14.1 months, and 1.18 years.
How to Read the Result
The total days is the most straightforward number—it is the exact count of 24-hour periods between the two dates (excluding the start day, including the end day). If you need to know “how many full months and leftover days,� you can derive that manually: 430 days is roughly 14 months (14 × 30.44 ≈ 426 days) plus about 4 days.
Be aware that the “months� output is an average-based decimal, not a count of calendar months. For example, from January 31 to February 28 is 28 days, which the calculator shows as 0.9 months, even though it spans two calendar months. If you need “whole calendar months,� you must count month boundaries separately.
Common Mistakes and Edge Cases
- Inclusive vs. exclusive counting: Some people count both the start and end dates (e.g., “from Monday to Friday� = 5 days), while this calculator counts the difference (4 days). Always clarify which convention you need.
- Leap years: February 29 adds an extra day. The date-difference method handles this automatically, but if you use a fixed 365-day year, you will be off by one day for each leap year in the range.
- Time-of-day issues: If you enter dates without times, the calculator assumes midnight. If you enter a date with a time (e.g., 2024-01-15 14:30), the result will include a fractional day, which is rounded down.
- Start after end: The calculator returns 0 days if the end date is earlier than the start date. It does not give negative values.
- Month-length variation: Using 30.44 days per month is an average; for a specific span, the actual number of calendar months may differ by a few days.
When to Use This Calculation
Date differences come up in many everyday situations:
- Project planning: How many days until a deadline, or how many weeks a task will take.
- Age calculation: Exact days lived, or age in years and months.
- Billing and subscriptions: Pro-rating charges based on days of service.
- Travel itineraries: Number of nights between check-in and check-out.
- Scientific or historical research: Time elapsed between two events.
For legal or financial matters, always confirm the exact counting convention (e.g., “30/360� vs. “actual/actual�) because a one-day difference can matter.
Limitations of the Formula
This calculator treats each day as exactly 24 hours. If you need to account for daylight saving time changes (which make some days 23 or 25 hours), the result may be off by one hour per transition. For most date-difference purposes, that is irrelevant.
Also, the “months� figure is an approximation. There is no universally accepted way to convert days to months because months have different lengths. If you need a precise number of calendar months (e.g., “from March 15 to June 15 is exactly 3 months�), you should count month boundaries manually, not rely on an average.
Frequently Asked Questions
How do I count days between two dates manually?
You can count the days by adding up the days in each month between the dates, remembering to include the start day if you want an inclusive count. For example, from Jan 15 to Mar 20: Jan has 17 remaining days (31−15+1 if inclusive), Feb has 28 (or 29 in a leap year), and Mar has 20 days, giving 65 days inclusive (or 64 if exclusive).
Why does the calculator show 14.1 months for 430 days?
Because it divides 430 by the average month length of 30.44 days. That gives 14.126, rounded to 14.1. This is an approximation; the actual calendar months between those dates (Jan 15 to Mar 20 of the next year) are 14 full months plus a few days.
What is the difference between “days� and “calendar days�?
“Days� here means the number of 24-hour periods. “Calendar days� usually means the number of dates on a calendar, which is the same thing unless you are counting business days (excluding weekends and holidays). This calculator does not exclude weekends or holidays.
How do I calculate business days between two dates?
Subtract the total days, then subtract the number of weekend days (usually Saturdays and Sundays) and any holidays. This calculator does not do that automatically; you would need to count weekends manually or use a separate business-day calculator.
Does the calculator handle dates before 1970?
Yes, JavaScript Date objects can handle dates from 1900 to 2099 reliably, and most other years as well. However, some browsers may have issues with dates before 1900 or after 2099. For most practical purposes, it works fine.
Why is the result off by one day sometimes?
This usually happens because of inclusive counting. If you expect to count both the start and end dates, you need to add 1 to the result. For example, from Monday to Friday is 4 days by difference, but 5 days if you include both Monday and Friday.
Related
Formula used
in d1 | Start date | yyyy-mm-dd | 2024-01-15 | 0 in d2 | End date | yyyy-mm-dd | 2025-03-20 | 0 out days | Total days | days | max(0, floor((d2 - d1) / 86400000)) | 0 out months | Full months | months | (floor((d2 - d1) / 86400000) - ( ( (d2.getUTCFullYear() - d1.getUTCFullYear()) * 12 + (d2.getUTCMonth() - d1.getUTCMonth()) ) > 0 ? 0 : 0 )) / 30.44 | 1 out years | Years + months | - | (d2 - d1) / 31556952000 | 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.