DATEDIF
Calculate the difference between two dates as complete years, months, or days using DATEDIF.
Spreadsheet editor
Spreadsheet editor
Syntax
=DATEDIF(start_date, end_date, unit)
Returns: Number Arguments
| Argument | Required | Description |
|---|---|---|
| start_date | Yes | The starting date of the period to measure. |
| end_date | Yes | The ending date of the period. Must be on or after start_date. |
| unit | Yes | A text code that determines what to count: "Y" (full years), "M" (full months), "D" (total days), "MD" (days ignoring months/years), "YM" (months ignoring years/days), "YD" (days ignoring years). |
About
The most common use is calculating age or tenure. For example, =DATEDIF(A2, TODAY(), "Y") gives someone's age in complete years from their birthdate. You can also combine multiple DATEDIF calls to display results like "2 years, 3 months" by using "Y" and "YM" together.
DATEDIF is a legacy function that doesn't appear in Excel's autocomplete, but it works in all versions. One known issue: the "MD" unit can return incorrect or negative results in some edge cases, so for total day counts, subtraction or DAYS is more reliable. The function returns a #NUM! error if start_date is later than end_date.
Exercises using DATEDIF
Examples
Date order matters
Spreadsheet editor
Why "MD" can be misleading
Spreadsheet editor
Building a readable tenure string
Spreadsheet editor
Watch out for
Start date is after end date
If start_date is later than end_date, DATEDIF returns a #NUM! error. This often happens when dates come from user input or when TODAY() is used as the start date instead of the end.
→ Make sure start_date is always the earlier date. Wrap the formula with IFERROR to handle cases where the order might vary.
The "MD" unit gives inaccurate results
The "MD" unit, which counts days while ignoring months and years, can return negative numbers or wrong values in certain edge cases. Microsoft has acknowledged this as a known issue.
→ Avoid "MD" for calculations where accuracy matters. If you need the total number of days between two dates, use simple subtraction or the DAYS function instead.
Function doesn't appear in autocomplete
Typing =DATEDIF in a cell won't trigger Excel's autocomplete suggestions or show argument hints. This makes it easy to accidentally misspell the name or mix up the argument order.
→ Type the full function manually: =DATEDIF(start_date, end_date, unit). Remember that start_date always comes first.
Dates stored as text
If your date cells contain text strings instead of real date values, DATEDIF may return an error or give unexpected results.
→ Check that cells are formatted as dates, not text. Use DATEVALUE to convert text representations of dates into serial numbers that DATEDIF can work with.