To count the number of months between two dates in Excel, use the DATEDIF function with the "m" unit, like this: =DATEDIF(A1, B1, "m"). This returns the complete calendar months between the start date in A1 and the end date in B1. If you need a more flexible count that handles partial months or specific day-of-month logic, you can combine YEAR, MONTH, and DAY functions. This guide covers the main formulas, how to adjust for different counting methods, and common pitfalls.

What You'll Need

  • Excel (any recent version, including Microsoft 365, Excel 2019, 2016, or older). The steps are identical across versions.
  • Two date cells: one for the start date and one for the end date. These can be typed directly into the formula or referenced from cells.
  • Basic familiarity with entering formulas in a cell (typing an equals sign and selecting cells).

Step-by-Step

Method 1: Simple Whole Months with DATEDIF

  1. Identify your start and end dates. For example, put a start date in cell A1 (like 2024-01-15) and an end date in cell B1 (like 2024-06-20).
  2. Select the cell where you want the result (e.g., C1).
  3. Type the formula: =DATEDIF(A1, B1, "m"). Press Enter.
  4. Read the result. Excel returns the number of complete months between the two dates. In the example, it returns 5 (January 15 to June 15 is 5 months, and the extra days from June 15 to June 20 are ignored).

How DATEDIF counts: It counts the number of month boundaries crossed. The day of the month is ignored for the month count, but the end date must be greater than or equal to the start date. If the end date is earlier, the formula returns an error (#NUM!).

Method 2: Months Including Partial Months (Decimal)

If you want a decimal result like 5.5 months (meaning 5 full months plus half a month), use a formula that calculates the difference in days and divides by the average month length (30.44 days).

  1. Use the formula: =(B1 - A1) / 30.44. This gives a decimal number of months based on the average month length.
  2. Format the result as a number with decimal places if needed (Home > Number > Increase Decimal).

Note: This method is approximate because months vary from 28 to 31 days. For precise month counting, use DATEDIF.

Method 3: Months with Day-of-Month Logic (e.g., from the 15th to the 15th)

Sometimes you need to count months only when the day of the month matches (like from the 15th to the 15th). Use a formula that checks the day.

  1. Use this formula: =DATEDIF(A1, B1, "m") + (DAY(B1) >= DAY(A1)). This adds 1 if the end day is greater than or equal to the start day, effectively counting the month when the day has been reached.
  2. Example: Start 2024-01-15, End 2024-06-20. DATEDIF gives 5, DAY(B1)=20, DAY(A1)=15, so 20>=15 is TRUE (1), total 6. That means you count June as a full month because the 20th is past the 15th.

Method 4: Months Between Dates in Google Sheets (Same Formula)

The DATEDIF function works identically in Google Sheets. Enter the same formula =DATEDIF(A1, B1, "m") and it will return the same result. The steps above apply directly.

Common Mistakes

  • Reversing the start and end dates. DATEDIF requires the start date first. If you swap them, you get an error or a negative number (in some versions). Always put the earlier date first.
  • Using the wrong unit. DATEDIF uses "m" for months, "d" for days, "y" for years. Using "M" (uppercase) also works, but "m" is standard. Do not use "mo" or "month"—they cause errors.
  • Forgetting that DATEDIF ignores days. If you want to count a month only when the full month has passed, DATEDIF does that. But if you need to include the end month even if it's not complete, you must adjust with the DAY formula as shown.
  • Using the DATEDIF function in older Excel without activation. DATEDIF is a hidden function in Excel but still works. If you type it manually, it's fine. If you use the function wizard, you may not find it, but typing it works.

Tips

  • Use cell references instead of typing dates in the formula. This makes it easier to update and avoids date format issues.
  • Format your date cells as dates (right-click > Format Cells > Date). If Excel stores them as text, the formula may not work. You can test by checking if the cell aligns left (text) or right (date).
  • For a quick count without formulas, use the DATEDIF in a helper column if you have many rows. Drag the formula down.
  • If you need the result as text like "5 months", use =DATEDIF(A1,B1,"m")&" months".
  • For years and months together, use =DATEDIF(A1,B1,"y")&" years, "&DATEDIF(A1,B1,"ym")&" months".

Troubleshooting

If the formula returns #NUM!: This means the start date is later than the end date. Swap the dates or correct the input.

If the formula returns #VALUE!: This usually means one of the cells contains text that looks like a date but isn't recognized. Ensure the cells are formatted as dates (select the cells, press Ctrl+1, choose Date). If they are text, convert them using DATEVALUE: =DATEDIF(DATEVALUE(A1), DATEVALUE(B1), "m").

If the result seems off by one: Remember DATEDIF counts complete months. If you expected 6 months from Jan 15 to Jul 14, DATEDIF gives 5 because July 15 hasn't been reached. Use the DAY adjustment formula if you need to count the month as soon as the day passes.

If the formula works but shows 0 for dates in the same month: That's correct. From Jan 5 to Jan 25, there are 0 complete months. If you want to count 1 for any part of a month, use =IF(DAY(B1)>=DAY(A1), DATEDIF(A1,B1,"m"), DATEDIF(A1,B1,"m")+1).

If you are using Excel for Mac: The DATEDIF function works the same. If you get a #NAME? error, make sure you typed the function name correctly (no spaces).

Frequently Asked Questions

Does DATEDIF count the end month?

No, DATEDIF counts complete months between the start and end dates. It does not include the end month unless the end date is on the same day of the month as the start date or later. For example, from Jan 15 to Feb 14 is 0 months; from Jan 15 to Feb 15 is 1 month.

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

Add 1 to the DATEDIF result: =DATEDIF(A1,B1,"m")+1. This counts both the start and end months as full months, regardless of the day.

Can I count months between dates in a pivot table?

Yes, but you need to add a calculated field or a helper column with the DATEDIF formula. Pivot tables don't have a built-in month difference function.

Is there a way to count months between dates without DATEDIF?

Yes, you can use =(YEAR(B1)-YEAR(A1))*12 + MONTH(B1)-MONTH(A1). This gives the number of month boundaries crossed, similar to DATEDIF but without the day logic. It may give a different result if the day of the month is earlier in the end date.

Why does my DATEDIF return a negative number?

DATEDIF does not return negative numbers; it returns #NUM! if the start date is after the end date. If you see a negative number, you might be using a different formula like the YEAR/MONTH method, which can go negative if the end month is earlier.

Can I count months between dates in Excel Online?

Yes, DATEDIF works in Excel for the web. Enter the same formula and it will calculate correctly.