← All how-to recipes

How to calculate the number of months between two dates

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Count whole months between dates — tenure, subscription length, loan periods.

The formula

AppFormulaNotes
Excel (desktop)=DATEDIF(A2,B2,"m")Counts COMPLETE months. For total including partial: use YEARFRAC*12 or the calendar-month formula below.
Google Sheets=DATEDIF(A2,B2,"m")Identical.
LibreOffice Calc=DATEDIF(A2,B2,"m")Identical.

How it works

DATEDIF with unit "m" counts COMPLETED months: Jan 15 to Jul 10 is 5 whole months, not 6, because the day-of-month (15th) hasn't been reached in July yet. If you instead want the difference in calendar months regardless of day — treating any part of a month as a month — use =(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2), which gives 6 here. Pick based on whether partial months should count. DATEDIF is undocumented in Excel's wizard but works in all three apps.

Verified, not just documented

We ran =DATEDIF(DATE(2026,1,15),DATE(2026,7,10),"m") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 5 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 5 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

DATEDIF — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons