Months in role, not days (DATEDIF)

Medium Math
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

HR reports tenure in whole months, so a partial month must not round up. The start and end dates for Ana are in B2 and C2 as ISO text. Put her completed months in the Months in role cell D2.

Whole months only — a period that ends on the 14th when it started on the 15th has not gained its final month.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
ABCD
1 EmployeeStartEndMonths in role
2 Ana2023-03-152026-01-15
3 Ben2024-07-012026-01-31
4 Cleo2025-09-012026-01-15

Notes

DATEDIF(start, end, "m") counts complete months between two dates. It is a compatibility function: Excel has it and never lists it in autocomplete, Google Sheets has it too. "m" gives months, "y" years, "ym" the leftover months after whole years — which is why the two-argument-chain version works.

How to approach

Your answer goes in D2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cell is D2
  2. DATEDIF takes start, end, and a unit string
  3. The unit for whole months is "m"
  4. Shape: =DATEDIF(?, ?, ?)

Official solutions

Show 2 solutions — try it yourself first

Approach 1: DATEDIF with the month unit

=DATEDIF(B2, C2, "m")

From 2023-03-15 to 2026-01-15 is 34 complete months: three years plus ten months. Because both dates fall on the 15th, no partial month is dropped.

Approach 2: years times twelve plus the leftover months

=DATEDIF(B2, C2, "y")*12 + DATEDIF(B2, C2, "ym")

"y" gives 2 whole years (24 months) and "ym" gives the 10 months on top; 34 is the same answer built from two units. Useful when you also want to print "2 years 10 months".

Function guide

Related practice

FAQ

How do I calculate months between two dates in Excel?

=DATEDIF(start, end, "m"). It counts complete months, so 2026-01-15 to 2026-02-14 is 0, not 1.

Why is DATEDIF not in Excel's function list?

It is a Lotus 1-2-3 compatibility function: Excel supports it but does not offer autocomplete or help for it. Type the name in full and the formula still works.