What is the DATEDIF function?
=DATEDIF(start_date, end_date, unit)DATEDIF counts how many years, months or days lie between two dates. It is widely used for "complete" periods such as ages, years of service and contract lengths.
According to Microsoft, DATEDIF is kept to support old workbooks from Lotus 1-2-3, so it does not appear in the function list or AutoComplete. Typing the name directly works normally. Microsoft does not recommend the "MD" unit because it can give wrong results, so this playground leaves it out.
Arguments
- start_date
- The first date of the period, such as a date of birth or start date.
- end_date
- The last date of the period. Use TODAY() to measure up to today. Earlier than start_date gives #NUM!.
- unit
- "Y" complete years, "M" complete months, "D" days, "YM" months left after whole years, "YD" days ignoring the year. Write it in quotes.
DATEDIF examples
Example 1. Age
=DATEDIF(B2, TODAY(), "Y")Complete years from the date of birth in B2 to today. The age goes up only after the birthday.
Example 2. Service as "x years y months"
=DATEDIF(B2, TODAY(), "Y") & " years " & DATEDIF(B2, TODAY(), "YM") & " months"Joins the years and the remaining months.
Example 3. Example from Microsoft
=DATEDIF("2001-06-01", "2002-08-15", "YD")Ignoring the year, June 1 to August 15 is 75 days.
Common mistakes
Dates in the wrong order
If start_date is later than end_date you get #NUM!. Unlike DAYS, it does not return a negative number.
Leaving out the quotes
DATEDIF(A2, B2, Y) without quotes gives #NAME?. Write "Y".
Using "MD"
"MD" for remaining days can give wrong values for some dates. Microsoft suggests subtracting the first day of the end date's month from the end date instead.
FAQ
- Why is it not in the function list?
- It is kept for compatibility, so it does not appear in AutoComplete or the Insert Function dialog. Type =DATEDIF( directly.
- Just need the number of days?
- =end_date-start_date or DAYS(end_date, start_date) is enough.