ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Dates
  3. How to Calculate Months Between Two Dates

How to Calculate Months Between Two Dates

By ExcelReady Team·Updated November 1, 2026·6 min read

The short answer

To count the whole months between two dates in Excel, use =DATEDIF(B2,C2,"m") with the start date first. For partial months as a decimal, use =YEARFRAC(B2,C2)*12. To count calendar months regardless of the day, use =(YEAR(C2)-YEAR(B2))*12+MONTH(C2)-MONTH(B2). Each method answers a slightly different question, so pick the one that matches yours.

Key takeaways

  • =DATEDIF(B2,C2,"m") counts complete months; the start date must come first.
  • =YEARFRAC(B2,C2)*12 gives months with a decimal, such as 13.83.
  • =(YEAR(C2)-YEAR(B2))*12+MONTH(C2)-MONTH(B2) counts calendar month changes and ignores the day.
  • DATEDIF returns #NUM! when the start date is after the end date.
  • Use "y" and "ym" in DATEDIF to show years and leftover months, like 1 year 1 month.
On this page+
  1. Which formula should you use?
  2. How to count whole months with DATEDIF
  3. How to show years and months together
  4. How to get months with decimals using YEARFRAC
  5. How to count calendar months between dates
  6. What about the end of the month?
  7. Common mistakes with months between dates
  8. Practise it

There are three ways to count the months between dates in Excel, and each answers a slightly different question. DATEDIF counts complete months, YEARFRAC gives months with a decimal, and a YEAR and MONTH formula counts calendar months. This guide shows all three on the same contract dates, so you can pick the right one for tenure, billing or project length.

Which formula should you use?#

Choose the formula by the question you are answering. Here are all three on a contract that runs from 15 January 2023 to 10 March 2024:

QuestionFormulaResult
How many full months have passed?=DATEDIF(B2,C2,"m")13
How many months, with a fraction?=YEARFRAC(B2,C2)*1213.83
How many calendar months apart?=(YEAR(C2)-YEAR(B2))*12+MONTH(C2)-MONTH(B2)14

The results differ because the contract ends on the 10th, five days before the 15th. DATEDIF doesn't count the last, unfinished month. The calendar formula ignores days and just counts how many times the month changes. YEARFRAC sits in between.

The methods don't always disagree. A contract from 1 February 2024 to 31 August 2024 gives 6 with both DATEDIF and the calendar formula, because it starts on the first day of a month. Most people would call that 7 months of work, though, since it covers February to August in full. That's the inclusive count, covered below. Decide which answer your report needs before you choose the formula.

If you need days rather than months, see how to count the days between two dates.

How to count whole months with DATEDIF#

DATEDIF counts complete months between a start date and an end date. The syntax is:

Excel formula
=DATEDIF(start_date, end_date, "m")

The start date comes first and the unit goes in double quotes. For the contract above:

Excel formula
=DATEDIF(B2,C2,"m")

The result is 13. From 15 January 2023, the 13th full month ends on 15 February 2024. The 14th month would end on 15 March 2024, which is after the end date, so it doesn't count.

DATEDIF is a hidden function. Excel doesn't list it in AutoComplete or show its arguments as you type, but it works in every current version on Windows and Mac. Just type the full formula. The DATEDIF function guide lists every unit.

DATEDIF returns #NUM! if the start date is after the end date. If you see that error, the two dates are the wrong way round.

How to show years and months together#

Combine two DATEDIF units to show a length like "1 year, 1 month". The "y" unit counts whole years, and "ym" counts the months left over after those years:

Excel formula
=DATEDIF(B2,C2,"y")&" years, "&DATEDIF(B2,C2,"ym")&" months"

For the contract, this returns 1 years, 1 months: 13 months is 1 full year plus 1 more month. The wording isn't perfect for 1, but it's clear and common in HR reports. The same approach is used for employee service time in the guide to calculating age and tenure.

How to get months with decimals using YEARFRAC#

YEARFRAC returns the fraction of a year between two dates. Multiply by 12 to turn it into months:

Excel formula
=YEARFRAC(B2,C2)*12

For the contract, the result is 13.83 months. This is useful when you bill or pro-rate by month and need the part month too.

By default YEARFRAC uses a 30/360 day count, which treats every month as 30 days. Add a third argument to change the method: =YEARFRAC(B2,C2,1)*12 uses the actual number of days, which gives about 13.79 here. For a whole number, wrap the result in ROUND, ROUNDDOWN or ROUNDUP. The YEARFRAC guide explains each basis option.

How to count calendar months between dates#

Use YEAR and MONTH when only the month matters, not the day. This formula counts how many month boundaries lie between the dates:

Excel formula
=(YEAR(C2)-YEAR(B2))*12+MONTH(C2)-MONTH(B2)

For January 2023 to March 2024, that's 1 year × 12, plus 3 − 1, which is 14. It returns 14 whether the contract started on the 1st or the 31st of January.

This is the right choice for reports by month, such as "how many monthly invoices fall between these dates". To count both the first and the last month, add 1. January to March then counts as 3 months, not 2.

What about the end of the month?#

DATEDIF can give surprising results near the end of a month. From 31 January 2024 to 29 February 2024, =DATEDIF(B2,C2,"m") returns 0. February has no 31st, so Excel decides a full month hasn't passed.

If your dates are often month-ends, the calendar formula is more predictable. When you need a date a set number of months later, rather than a count, use EDATE: =EDATE(B2,6) returns the date six months after B2. The guide to adding days, months and years to a date covers EDATE in detail.

Common mistakes with months between dates#

Most problems come from argument order or from the dates themselves. Check these:

  1. Start and end swapped. DATEDIF needs the earlier date first, or it returns #NUM!.
  2. Unit without quotes. Write "m", not m. Without quotes, Excel returns #NAME?.
  3. Text dates. If a date is stored as text, the formulas return #VALUE!. Convert it to a real date first.
  4. Result looks like a date. If 13 shows as 13/01/1900, format the cell as General or Number.
  5. Counting up to today. Use TODAY() as the end date, as in =DATEDIF(B2,TODAY(),"m"). The result changes every day. For counting down to a future date, see days until a deadline.

Practise it#

Date differences come up in HR, finance and project questions in many job tests, and DATEDIF's argument order trips people up under time pressure. Practise counting days and months between dates in a live spreadsheet: you type the formula and it checks your answer instantly. Or try the exercise on this page first.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

How many complete months has each contract run? Click D2 and use DATEDIF with the start date in B2, the end date in C2 and the unit "m".

fx
ABCDE
1
Contract
Start
End
Months
2
Alpha Ltd
44941
45361
3
Beta Co
45323
45535
4
Gamma Inc
44732
45662
5
6
7

Tip: Start date first, end date second, then the unit "m" in double quotes.

Practise this in a lesson

LessonDays between dates: DAYS, DATEDIF and TODAYMeasure the gap between two dates in days, months and years, and calculate tenure as of today.Function guideDATEDIFCalculate tenure, age and contract length with DATEDIF. Learn every unit (Y, M, D, YM), the hidden-function quirks, and practice live.

Frequently asked questions

How do I calculate the number of months between two dates in Excel?

+

Use =DATEDIF(start_date,end_date,"m"), for example =DATEDIF(B2,C2,"m"). It returns the number of complete months between the two dates.

Why doesn't DATEDIF show up when I type it?

+

DATEDIF is an older function that Excel keeps for compatibility. It works in all current versions, but Excel doesn't suggest it or show its arguments, so type the whole formula yourself.

How do I get months between dates with decimals?

+

Use =YEARFRAC(B2,C2)*12. YEARFRAC returns the fraction of a year between the dates, and multiplying by 12 turns it into months, such as 13.83.

How do I count months including the start and end month?

+

Use the calendar formula and add 1: =(YEAR(C2)-YEAR(B2))*12+MONTH(C2)-MONTH(B2)+1. January to March then counts as 3 months.

Why does DATEDIF return #NUM!?

+

The start date is later than the end date. DATEDIF can't return a negative number, so swap the two dates or check that the cells are in the right order.

Sources

  • DATEDIF function - Microsoft Support
  • YEARFRAC function - Microsoft Support
  • MONTH function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Which formula should you use?
  2. How to count whole months with DATEDIF
  3. How to show years and months together
  4. How to get months with decimals using YEARFRAC
  5. How to count calendar months between dates
  6. What about the end of the month?
  7. Common mistakes with months between dates
  8. Practise it

Keep reading

Dates· 6 min read

Days Between Two Dates in Excel (and DATEDIF)

To count the days between two dates in Excel, subtract the earlier date from the later one: =C2-B2. DAYS does the same with the end date first: =DAYS(C2,B2). For whole months or years, use DATEDIF with the start date first and a unit in quotes, like =DATEDIF(B2,C2,"Y").

Dates· 6 min read

Add Days, Months or Years to a Date in Excel

To add days to a date in Excel, just add the number: =A2+30. For working days, use =WORKDAY(A2,10). To add months, use =EDATE(A2,3), which handles months of different lengths. To add years, use =EDATE(A2,12*n), for example =EDATE(A2,24) for two years. Use negative numbers to go back in time.

Dates· 6 min read

Calculate Age or Years of Service in Excel

To calculate age in Excel, use =DATEDIF(B2,TODAY(),"Y"), where B2 is the birth date. It counts complete years, so the age only goes up on the birthday. Years of service work the same way with the hire date. For a report that must not change, replace TODAY() with a fixed "as of" date cell.

More on dates

  • Count Working Days With NETWORKDAYS and WORKDAY
  • Get the Quarter From a Date in Excel
  • TODAY Function in Excel: Always-Current Dates
  • WEEKDAY in Excel: Find Weekends and Day Names
  • YEAR, MONTH and DAY in Excel: Split a Date Into Parts
  • YEARFRAC in Excel: Part of a Year Between Two Dates
All dates articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free