Excel functions · Dates
DATEDIF function in Excel
DATEDIF calculates the number of whole years, months or days between two dates, which makes it the usual way to work out age or length of service. It's a hidden function: Excel doesn't suggest it as you type, so you enter it in full, and the unit you choose ("Y", "M", "D" and others) decides what it counts.
Last reviewed
Syntax
=DATEDIF(start_date, end_date, unit)- start_daterequired
- The earlier date.
- end_daterequired
- The later date. It must not be before start_date.
- unitrequired
- What to count, in quotes: "Y" whole years, "M" whole months, "D" days, "YM" months left after whole years, "YD" days left after whole years, "MD" days left after whole months.
- Use TODAY() as end_date for an age or tenure that stays current.
- Microsoft's own page warns that the "MD" unit can return a negative number, a zero or an inaccurate result; avoid it.
- For plain day counts, end_date - start_date gives the same as "D".
Which versions have DATEDIF
Every current Excel version: Microsoft 365, Excel for the web, Excel 2024, 2021, 2019 and 2016, on Windows and Mac.
DATEDIF works in every Excel version, but it isn't listed in Insert Function or formula AutoComplete, so you type it in full. Microsoft keeps it for compatibility with Lotus 1-2-3.
| Version | Has it |
|---|---|
| Microsoft 365 (Windows and Mac) | Yes |
| Excel for the web | Yes |
| Excel 2024 | Yes |
| Excel 2021 | Yes |
| Excel 2019 | Yes |
| Excel 2016 | Yes |
Google Sheets
Google Sheets has DATEDIF, documented and listed like any other function, with the same units.
Examples
The examples use this sample sheet.
| Row | A | B | C |
|---|---|---|---|
| 1 | Employee | Start date | Review date |
| 2 | Nadia | 2019-03-15 | 2026-11-20 |
1.Whole years of service
=DATEDIF(B2, C2, "Y")Result: 7
From 15 March 2019 to 20 November 2026 is 7 full years; the 8th isn't complete until March 2027.
2.Total whole months
=DATEDIF(B2, C2, "M")Result: 92
7 years (84 months) plus 8 months, from 15 March to 15 November.
3.Years and months as text
=DATEDIF(B2, C2, "Y")&" years, "&DATEDIF(B2, C2, "YM")&" months"Result: 7 years, 8 months
"YM" counts the months left over after the whole years.
Common errors and fixes
| Error | Why it happens | Fix |
|---|---|---|
| #NUM! | start_date is after end_date. | Swap the dates, or wrap the formula in IF to check which is earlier. |
| #VALUE! | A date is text that Excel can't read as a date. | Convert it with DATEVALUE, or re-enter it as a real date. |
| #NUM! from a typo in unit | unit isn't one of Y, M, D, YM, YD or MD, or is missing its quotes. | Put the unit in quotes: "Y". |
Do it with GPTExcel
Skip writing DATEDIF by hand
Upload your Excel or CSV file to Chat and ask in plain English. GPTExcel writes the formula for your file and your version of Excel or Google Sheets.
Work out each employee's tenure in years and months as of today.
Done. I used DATEDIF on your sheet and checked the results against your data.
- Written for your platform and version
- Checked against your actual data
- Newest functions looked up in official docs
DATEDIF questions
- Why can't I find DATEDIF in Excel?
- Excel doesn't list DATEDIF in Insert Function or suggest it as you type, but it works in every version. Type it in full, such as =DATEDIF(B2, C2, "Y").
- How do I calculate age in Excel?
- Use =DATEDIF(birth_date, TODAY(), "Y"). It counts only full years, so the age goes up on the birthday.
- Does DATEDIF work in Google Sheets?
- Yes. Google Sheets documents DATEDIF in its function list, with the same units as Excel.
Skip the formula hunt
Upload a spreadsheet and ask in plain English. Free plan, no credit card.
Start free