How to use DATEDIF in Excel: date difference, age and years of service
DATEDIF returns the number of complete years, months or days between two dates. Ideal for calculating age, length of service and contract terms.
Syntax
=DATEDIF(start_date, end_date, unit)
- start_date — The earlier date: date of birth, hire date, contract start.
- end_date — The later date: today (TODAY()), a report date. If it is earlier than start_date you get #NUM!.
- unit — The unit of the result, in quotes: "Y" — years, "M" — months, "D" — days, "YM", "MD", "YD" — remainders.
Example
Formula:
=DATEDIF(B2,C2,"Y")→ result: 29
How DATEDIF works
DATEDIF counts only COMPLETE units. In the example, Aziz was born on 15 March 1995 and the “as of” date is 10 March 2025. The difference in years looks like 30, but his 2025 birthday (15 March) hasn’t come yet, so the result is 29. It is a “hidden” function: Excel doesn’t list it among functions and shows no argument tooltip while you type. Still, it works fully in Excel 2016, 2019, 2021 and 365 — just type the name and arguments correctly.
Units: Y, M, D, YM, MD, YD
For the dates in the example (1995-03-15 → 2025-03-10): • "Y" — complete years: 29 • "M" — complete months: 359 • "D" — days: 10953 • "YM" — months left after complete years: 11 • "MD" — days left after complete months: 23 • "YD" — difference in days, ignoring years: 360 The unit always goes in quotes and is not case-sensitive. It can also come from a cell: =DATEDIF(B2,C2,E1).
Calculating age
Age as of today: =DATEDIF(B2,TODAY(),"Y") TODAY updates every day, so when you open the file tomorrow the age is still correct. In full: =DATEDIF(B2,TODAY(),"Y")&" years "&DATEDIF(B2,TODAY(),"YM")&" months" Simple division =(TODAY()-B2)/365 is unreliable: because of leap years, the age can be off by one around the birthday.
Years of service as “X years Y months”
The formula HR departments ask for most: =DATEDIF(B2,C2,"Y")&" years "&DATEDIF(B2,C2,"YM")&" months" For the example dates the result is “29 years 11 months”. If you need days too, append &" "&DATEDIF(B2,C2,"MD")&" days". For a seniority bonus, use the number itself: =DATEDIF(B2,C2,"Y") returns a number you can use in IF or VLOOKUP.
Common errors
• #NUM! — the start date is after the end date. Check the order of the arguments. • #VALUE! — a date was entered as text (for example, it’s left-aligned in the cell). Convert the column to a date format or use DATEVALUE. • #NAME? — the unit is missing its quotes: not Y but "Y". • The result looks like a date (e.g. 1/28/1900) — the cell has a date format. Switch it to General. • The "MD" unit can return wrong (even negative) results for some end-of-month dates — Microsoft itself advises against relying on it. If you need exact days, work them out with EDATE.
DATEDIF alternatives
• Days between dates: =C2-B2 or =DAYS(C2,B2) — DAYS takes the end date first, then the start date. • Fractional years: =YEARFRAC(B2,C2,1) → 29.99. Whole years of age: =INT(YEARFRAC(B2,C2,1)). • Working days: =NETWORKDAYS(B2,C2) — excludes weekends and holidays. • Add months to a date (contract end): =EDATE(B2,12) — the date exactly one year later. DATEDIF’s strength is that it counts “complete years and months” the way people do, which makes it the most convenient choice for age and service length.
Pro tips
• End-of-month trap: from 2025-01-31 to 2025-02-28, "M" = 0, because 28 < 31 and a full month hasn’t passed yet. • If both boundary days should count (e.g. vacation days), add 1: =DATEDIF(B2,C2,"D")+1. • Days until the next birthday: this year’s birthday is =DATE(YEAR(TODAY()),MONTH(B2),DAY(B2)); if it has already passed, add 1 to the year. • In a large table, put the “as of” date in one cell and lock it: =DATEDIF(B2,$F$1,"Y").
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.