The DATEDIF function
DATEDIF answers "how long between these two dates?" in complete years, months or days. It counts *whole* units, so someone one day short of their birthday is still the younger age.
It's an old function kept for compatibility, so Excel doesn't suggest it as you type. Type it in full and it works.
=DATEDIF(start_date, end_date, unit)
Arguments
- start_date
- The earlier date.
- end_date
- The later date. It must not be before
start_date. - unit
- What to count, in quote marks:
"Y"whole years,"M"whole months,"D"days,"YM"months left over after whole years,"MD"days left over after whole months,"YD"days since the last anniversary.
Try it
=DATEDIF(B2,C2,"Y") in D2. From 2 Sep 2019 to 14 Mar 2025 is 5 complete years (the 6th anniversary would be in September).
D2
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | Started | Left | Years | |
| 2 | Hannah Moss | 2 Sep 2019 | 14 Mar 2025 | 5 | |
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Edit the formula in D2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =DATEDIF(B2,C2,"M") | 66 | The same gap in complete months. |
| =DATEDIF(B2,C2,"Y")&" years, "&DATEDIF(B2,C2,"YM")&" months" | 5 years, 6 months | "YM" gives the months left over after the whole years. |
| =DATEDIF(B2,C2,"D") | 2020 | Total days, the same as C2-B2. |
| =DATEDIF(C2,B2,"Y") | #NUM! | The dates are the wrong way round: the start date must come first. |
Tips
- Age today:
=DATEDIF(A2,TODAY(),"Y"). - Join units for a readable length of service:
DATEDIF(B2,C2,"Y")&" years, "&DATEDIF(B2,C2,"YM")&" months". - For plain day counts,
=C2-B2or DAYS is simpler.
Common mistakes
- DATEDIF returns #NUM!.The start date is after the end date. Put the earlier date first, or swap them with MIN and MAX.
- The unit is ignored or gives #NUM!.The unit must be text in quote marks:
"Y", not Y. - "MD" gives odd or even negative answers near the end of a month.Microsoft itself warns that "MD" can be unreliable. Work out leftover days another way, such as
C2-EDATE(B2,DATEDIF(B2,C2,"M")).
In Google Sheets
Google Sheets has DATEDIF with the same units and documents it in its function help. As in Excel, a start date after the end date gives #NUM!.
Practise DATEDIF with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.