What the Months Between Dates Calculator does
This calculator counts the months between two dates: whole calendar months plus the days left over, the same span as decimal months, and the exact results Excel and Google Sheets give with DATEDIF and YEARFRAC. Enter a start and an end date and every version appears at once, with the rule behind each one written out.
Months are awkward because they are 28, 29, 30 or 31 days long, so different tools quietly disagree - most visibly when a date falls at the end of a month. Here the headline uses the anniversary rule with a stated end-of-month clamp, and a table beside it shows where spreadsheets give a different number and why. Everything runs in your browser.
How to use it
- Pick the start date and the end date, or press "End date = today" to measure up to today.
- Tick "Count the end date as a full day" when the end date itself is included, as with a lease from 1 November to 31 October or a contract that ends at the close of a day.
- Read the headline: whole months and remaining days. Below it are the same span in years-months-days, decimal months, total days and weeks.
- Check the notes. They appear when the end-of-month rule was used or when a spreadsheet would give a different answer.
- Use the table to copy the matching spreadsheet formula. It assumes the start date is in cell A1 and the end date in B1.
Reading the results
A whole month is complete when the calendar reaches the same day number in a later month. If that day does not exist - the 31st in a 30-day month, or the 29th to 31st in February - the month completes on the last day of that shorter month. So 31 January to 28 February 2023 is exactly one month here.
Spreadsheet DATEDIF with "M" only completes a month when the end day number reaches the start day number, so it reports 0 months for the same dates. Neither is wrong; they answer slightly different questions, and the note tells you which one your context expects.
Decimal months come in three flavours. The exact one divides the leftover days by the length of the month being counted; the average one divides total days by 30.4375 (365.25 / 12); the actual/actual one is YEARFRAC basis 1 x 12. They usually agree to one decimal place and differ in the second.
A negative "days over" figure in the DATEDIF row is a spreadsheet quirk, not your mistake: Microsoft's documentation warns that the "MD" unit can return negative or inaccurate results.
Worked example: 15 March 2020 to 20 October 2026, and the end-of-month case
From 15 March 2020 the anniversaries run 15 April, 15 May and so on. The 79th falls on 15 October 2026 (6 years x 12 + 7 months), and 20 October is 5 days later. Result: 79 months and 5 days, or 6 years 7 months 5 days.
The month being counted runs from 15 October to 15 November, which is 31 days, so the exact decimal is 79 + 5 / 31 = 79.16 months. The total span is 2,410 days, and 2,410 / 30.4375 = 79.18 average months.
DATEDIF agrees: "M" is (2026 - 2020) x 12 + (10 - 3) = 79, because the end day (20) is not before the start day (15), and "MD" is 20 - 15 = 5.
Now 31 January 2023 to 28 February 2023. February has no 31st, so the anniversary clamps to 28 February: 1 month and 0 days. DATEDIF "M" gives 0, because 28 is less than 31, and "MD" gives 28 - 31 + 31 = 28 days. YEARFRAC basis 1 is 28 / 365 = 0.0767 years, or 0.92 months.
Formulas and scoring rules
- Whole calendar months
months = largest m with addMonths(start, m) <= endaddMonths keeps the start day and clamps it to the last day of shorter months, always counting from the original start date.- Remaining days and exact decimal
days = end - addMonths(start, m); decimal = m + days / (addMonths(start, m + 1) - addMonths(start, m))- DATEDIF "M"
(y2 - y1) x 12 + (m2 - m1) - (1 if d2 < d1)- DATEDIF "MD"
d2 - d1, plus the length of the month before the end month when d2 < d1Reproduces the spreadsheet result, including its negative values for dates such as 31 January to 1 March.- Average-month decimal
days / 30.437530.4375 = 365.25 / 12, the average month length over the leap-year cycle used by many tools.- YEARFRAC basis 1
within a year: days / (366 if 29 Feb is spanned else 365); longer: days / average length of the calendar years touchedMultiplied by 12 for months. Displayed to 2 or 4 decimals; calculated unrounded.
Limitations: what the result does not prove
- Billing, interest and legal periods often follow their own conventions - 30/360 day counts, "clear months", business days or a contract's own definition. Check which one applies before relying on any figure here.
- Dates are whole calendar days. Times of day and time zones are not considered, so a span measured to the minute may differ by a day.
- Spreadsheet equivalents assume Excel's 1900 date system and the documented behaviour of DATEDIF and YEARFRAC; LibreOffice and other software may treat edge cases slightly differently.
- Dates follow the Gregorian calendar throughout, including for years before it was adopted in a given country.
Privacy: where your data goes
Everything you paste, type or drop is processed in this browser tab. It is not uploaded, logged, stored or sent to analytics. Session recording and tag-manager scripts are switched off on this page.
Standards and sources
- ISO 8601 - Date and time format - checked 19 Sep 2026
- Microsoft Support - DATEDIF function
- Microsoft Support - YEARFRAC function
- Google Docs Editors Help - DATEDIF
- David A. Wheeler - Excel YEARFRAC basis 1 algorithm (OASIS OpenDocument formula list, 2008)
Frequently asked questions
How do I calculate the number of months between two dates?
Count forward from the start date one month at a time, keeping the same day number, until the next step would pass the end date. That count is the whole months; the days from the last anniversary to the end date are the remainder. This page does it for you and also shows the decimal and spreadsheet versions.
What is the Excel formula for months between dates?
Use =DATEDIF(A1,B1,"M") for whole months, with the start date in A1 and the end date in B1. For months with a fraction use =YEARFRAC(A1,B1,1)*12. DATEDIF needs the start date first; if it is later than the end date Excel returns #NUM!. The same formulas work in Google Sheets.
How many months is 31 January to 28 February?
One month by the anniversary rule, because February has no 31st and the month is complete on its last day. Excel's DATEDIF "M" says 0, because it waits for the day number to reach 31. Which answer you need depends on whether you are counting calendar months or matching a spreadsheet.
Why does DATEDIF "MD" give a negative number?
Because of how it borrows days from the previous month. For 31 January to 1 March 2023 it computes 1 - 31 + 28 = -2. Microsoft's own documentation says the "MD" argument may give negative, zero or inaccurate results, so avoid it for anything that matters and use the remaining-days figure here instead.
How do I count months including the end date?
Tick "Count the end date as a full day". It moves the end of the span to the end of that day, so 1 January to 31 January becomes exactly one month and a lease from 1 November to 31 October becomes exactly 12 months, which is how most people describe those periods.
How many days are in an average month?
30.4375 days, which is 365.25 divided by 12 - the average over the four-year leap cycle. Some tools use 30.44 or 30.42 (365 / 12). Dividing total days by an average month gives a quick decimal, but it can be a little off from the calendar count for short spans.
Last reviewed by the A2Z.Tools team against the sources listed above.