How to calculate the number of months between two dates
✓ Verified in LibreOffice 25.8.7.3Count whole months between dates — tenure, subscription length, loan periods.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel | =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. Every formula here is confirmed by actually executing it.