DATEDIF function
Counts the complete years, months or days between two dates — the classic way to calculate age or length of service.
Available in All versions of Excel (an undocumented legacy function: it does not appear in the formula autocomplete list, but it works when typed in full)
In every Excel versionWorks in Google Sheets
Syntax
DATEDIF(start_date, end_date, unit)| Argument | What it means | |
|---|---|---|
start_date | Required | The earlier date, for example a birth date or hire date. |
end_date | Required | The later date. Must not be before start_date. |
unit | Required | A text code: "Y" complete years, "M" complete months, "D" days, "YM" months left over after whole years, "MD" days left over after whole months, "YD" days left over after whole years. |
Returns: A whole number: the count of complete units between the two dates.
How DATEDIF works
DATEDIF answers questions like "how old is this employee?" or "how many full months has this customer been subscribed?". Subtracting two dates only gives days, and dividing by 365 goes wrong around birthdays and leap years. DATEDIF counts completed units the way people do: someone born on 14 July 1988 is still 37 on 13 July 2026 and turns 38 the next day.
The function is a leftover from Lotus 1-2-3 compatibility, so Excel hides it: you will not see it in the autocomplete list and there is no argument tooltip. Type it in full and it works in every version. The unit argument controls what you get back; combining "Y", "YM" and "MD" gives the familiar "7 years, 7 months, 9 days" format used in HR letters.
Note that end_date must be on or after start_date, otherwise you get #NUM!. For a decimal number of years (useful for pro-rating) use YEARFRAC instead.
Examples
1Employee age in whole years
| A | B | C | |
|---|---|---|---|
| 1 | Employee | Birth date | Age |
| 2 | Maria Lopez | 1988-07-14 | 38 |
Result: 38
If today is 2 Dec 2026, Maria has passed her 38th birthday (14 July 2026), so DATEDIF returns 38. The result updates every day because of TODAY.
2Length of service as years, months and days
| A | B | C | |
|---|---|---|---|
| 1 | Hire date | End date | Service |
| 2 | 2019-04-23 | 2026-12-02 | 7 yrs, 7 mths, 9 days |
Result: 7 yrs, 7 mths, 9 days
"Y" counts 7 full years (to 23 Apr 2026), "YM" adds the 7 full months after that (to 23 Nov 2026), and "MD" counts the 9 remaining days to 2 Dec 2026.
3Complete months of a subscription
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer | Start | End | Months billed |
| 2 | Northwind Ltd | 2025-11-15 | 2026-12-02 | 12 |
Result: 12
From 15 Nov 2025 to 15 Nov 2026 is 12 complete months. The 17 days after that do not make a 13th complete month, so the answer is 12.
4Total days between two dates
| A | B | C | |
|---|---|---|---|
| 1 | Hire date | End date | Days |
| 2 | 2019-04-23 | 2026-12-02 | 2780 |
Result: 2780
"D" returns the plain day count, the same as =B2-A2 or =DAYS(B2,A2).
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | start_date is later than end_date, or the unit code is not one of the six valid codes. | Swap the dates or wrap with IF(A2>B2, "", DATEDIF(...)); check the unit spelling. |
#VALUE! | One of the dates is text that Excel cannot read as a date. | Convert it with DATEVALUE or DATE. |
Tips
- Avoid the
"MD"unit when the start day is near the end of a month (29th–31st): Microsoft itself warns it can return a negative number or a wrong day count. Calculate leftover days withB2-EDATE(A2,DATEDIF(A2,B2,"M"))instead. - The unit is not case-sensitive:
"y"and"Y"give the same result. - For anniversaries or birthdays coming up,
"YD"gives the days since the last anniversary; subtract it from 365 for a rough countdown.
Questions
Why can't I find DATEDIF in the function list?
Microsoft keeps it only for compatibility, so it is hidden from autocomplete and the Insert Function dialog. Typing it in full works in every Excel version.
How do I calculate age in Excel?
Use =DATEDIF(birth_date, TODAY(), "Y"). It returns complete years and handles leap years and birthdays correctly.
Does DATEDIF count the end date?
No. It counts complete units between the dates, so 1 Jan to 2 Jan is 1 day, not 2.
Google Sheets
DATEDIF also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
DATEDIF in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | DATO.FORSKEL |
| Dutch | DATUMVERSCHIL |
| Finnish | PVMERO |
| Hungarian | DÁTUMTÓLIG |
| Italian | DATA.DIFF |
| Norwegian (Bokmål) | DATODIFF |
| Polish | DATA.RÓŻNICA |
| Portuguese (Brazil) | DATADIF |
| Portuguese (Portugal) | DATADIF |
| Russian | РАЗНДАТ |
| Spanish | SIFECHA |