DATEDIF in Excel: Calculate Age, Tenure and Days Between Dates

DATEDIF is Excel’s hidden powerhouse for date calculations — it doesn’t appear in autocomplete, but it handles age, tenure, and date differences in years, months, or days with a single formula. This guide covers all 6 unit codes and 6 practical examples including full age strings, HR tenure banding, project duration, and birthday countdowns.

Need to calculate someone's exact age in Excel? Or find out how many years and months an employee has been with your company? The DATEDIF function is Excel's dedicated tool for calculating the difference between two dates in years, months, or days — and it handles all the calendar complexity for you. Despite being one of Excel's most useful date functions, DATEDIF is hidden: it does not appear in autocomplete and has no formula wizard. This guide teaches you the syntax, all six unit codes, and six real-world examples covering age, tenure, project duration, and more.

Hidden function: DATEDIF does not appear in Excel's formula autocomplete list — you must type the full formula manually. It works in all Excel versions from Excel 2000 through Microsoft 365. Always ensure the start date is earlier than the end date, or you will get a #NUM! error.

DATEDIF Syntax

The function takes three arguments — a start date, an end date, and a unit code that controls what is counted:

=DATEDIF(start_date, end_date, "unit")
ArgumentRequired?What it means
start_date Required The earlier date — a cell reference, a date in quotes, or a formula like DATE(1990,5,15). Must be earlier than end_date.
end_date Required The later date — usually a cell reference or TODAY() for calculations up to the present day.
unit Required A text code in double quotes that controls the type of interval returned. Six codes are available — see the table below.

The Six Unit Codes

The unit argument is what makes DATEDIF powerful. The first three codes return total intervals; the last three return remaining intervals after a larger unit has been counted — useful for building combined "X years, Y months, Z days" strings.

UnitReturnsTypical useExample result
"Y" Complete years between the two dates Age, tenure in years DATEDIF("1-Jan-2020", "28-Mar-2026", "Y") = 6
"M" Complete months between the two dates Subscription length, loan age DATEDIF("1-Jan-2020", "28-Mar-2026", "M") = 74
"D" Total days between the two dates Project duration, days overdue DATEDIF("1-Jan-2020", "28-Mar-2026", "D") = 2278
"YM" Remaining months after complete years Combined "Y years M months" strings DATEDIF("1-Jan-2020", "28-Mar-2026", "YM") = 2
"YD" Remaining days after complete years Days until next birthday/anniversary DATEDIF("1-Jan-2020", "28-Mar-2026", "YD") = 87
"MD" Remaining days after complete months Final days in a "Y yr M mo D days" string DATEDIF("1-Jan-2020", "28-Mar-2026", "MD") = 27
Avoid "MD" in important work: Microsoft documents that the "MD" unit can return inaccurate results in certain date combinations. For precise day-level calculations in the last portion of a combined string, use the alternative formula shown in Example 4 instead.

Example 1: Calculate Age from Date of Birth

The most common use of DATEDIF is calculating a person's current age in complete years. Using TODAY() as the end date means the result updates automatically every day.

1
Calculate current age in years from a date of birth
#
A — Name
B — Date of Birth
C — Age (formula)
2
Sarah
15-May-1990
35
3
James
22-Nov-1985
40
4
Priya
03-Aug-2000
25
Age in complete years — updates daily: =DATEDIF(B2, TODAY(), "Y") With label: =DATEDIF(B2, TODAY(), "Y") & " years old"
The "Y" unit returns only complete years — the formula automatically accounts for whether the birthday has occurred yet this calendar year.
Age as of a specific date: Replace TODAY() with any date cell to calculate age as of that date — useful for eligibility checks, insurance reports, and historical age verification.

Example 2: Full Age in Years, Months, and Days

A single DATEDIF call returns one unit. Combine three calls — "Y", "YM", and "YD" — with the ampersand operator to build a full human-readable age string like "35 years, 10 months, 13 days".

2
Build a "X years, Y months, Z days" age string
Full age string from DOB in B2 to today: =DATEDIF(B2,TODAY(),"Y") & " years, " &DATEDIF(B2,TODAY(),"YM") & " months, " &DATEDIF(B2,TODAY(),"YD") & " days"
Date of birth (B2)
Result
15-May-1990
35 years, 10 months, 13 days
22-Nov-1985
40 years, 4 months, 6 days
How the units work together: "Y" gives total complete years. "YM" gives remaining months after those years are removed. "YD" gives remaining days after those years are removed. Each unit builds on the previous one to produce a non-overlapping breakdown.

Example 3: Calculate Employee Tenure

HR teams use DATEDIF to calculate service length for payroll banding, leave entitlement, and performance reviews. The formula works identically whether the employee is still active (use TODAY()) or has left (use their last day).

3
Calculate years and months of service for each employee
#
A — Employee
B — Hire Date
C — Tenure
2
Ana Torres
12-Mar-2018
8 yrs, 0 mo
3
Ben Khalid
01-Sep-2021
4 yrs, 6 mo
4
Chloe Wang
15-Jan-2024
2 yrs, 2 mo
Tenure in "X yrs, Y mo" format (C2): =DATEDIF(B2, TODAY(), "Y") & " yrs, " &DATEDIF(B2, TODAY(), "YM") & " mo" Tenure in complete years only (for banding / reporting): =DATEDIF(B2, TODAY(), "Y") Tenure band using IF (for leave entitlement tiers): =IF(DATEDIF(B2,TODAY(),"Y")>=10, "Senior", IF(DATEDIF(B2,TODAY(),"Y")>=5, "Mid", "Junior"))

Example 4: Count Days Between Two Dates

For total days between two dates, you can simply subtract the start date from the end date — Excel stores dates as numbers, so subtraction gives days directly. DATEDIF with "D" does the same thing. Both approaches are shown here.

4
Calculate total days — project duration, days overdue, SLA tracking
Start (A)
End (B)
DATEDIF "D"
Simple subtract
01-Jan-2026
28-Mar-2026
86 days
86 days
15-Feb-2026
28-Mar-2026
41 days
41 days
Using DATEDIF: =DATEDIF(A2, B2, "D") Simple subtraction (same result, easier to read): =B2 - A2 Days remaining until a deadline: =B2 - TODAY() Days overdue (negative = ahead of schedule): =TODAY() - B2
Format the result: When you subtract two dates, Excel may format the result cell as a date instead of a number. Select the cell, press Ctrl+1, and choose Number format to see the day count correctly.

Example 5: Count Complete Months Between Dates

Use "M" to count total complete months — useful for subscription billing, loan tracking, and any scenario where partial months do not count. Combine with "YM" to show the remaining months after full years.

5
Count complete months — subscriptions, loans, contract length
#
A — Start
B — End
Total months
After years
2
01-Jan-2024
28-Mar-2026
26 months
2 months
3
15-Aug-2023
28-Mar-2026
31 months
7 months
Total complete months between two dates: =DATEDIF(A2, B2, "M") Remaining months after complete years (for "2 years, 3 months" strings): =DATEDIF(A2, B2, "YM") Months until a future date (e.g. contract end in B2): =DATEDIF(TODAY(), B2, "M") & " months remaining"

Example 6: Next Birthday and Anniversary Countdown

The "YD" unit returns days elapsed since the last anniversary of a date within the current year. Subtract this from 365 to get a countdown to the next birthday or work anniversary — useful for HR alerts and customer loyalty programmes.

6
Days until next birthday or work anniversary
Days until next birthday (from DOB in A2): =365 - DATEDIF(A2, TODAY(), "YD") Next birthday date: =DATE(YEAR(TODAY())+1, MONTH(A2), DAY(A2)) Alert if birthday is within the next 30 days: =IF(365 - DATEDIF(A2,TODAY(),"YD") <= 30, "Birthday soon!", "") Work anniversary countdown (hire date in B2): =365 - DATEDIF(B2, TODAY(), "YD")
Add this formula to an HR dashboard with conditional formatting to highlight employees with birthdays or work anniversaries in the next 30 days automatically.
Leap year note: Using 365 as the divisor is accurate for most cases. For precise leap-year handling, calculate the next birthday date directly using the DATE(YEAR+1, MONTH, DAY) formula shown above and subtract TODAY() from it.

Troubleshooting DATEDIF Errors

#NUM! error

The start_date is greater than the end_date. DATEDIF requires the earlier date first. Check that your date columns are not reversed, and add an IF guard if needed: =IF(A2>B2, "Check dates", DATEDIF(A2,B2,"Y")).

#VALUE! error

One of the date arguments is stored as text rather than a real Excel date. Press Ctrl+` to check — real dates show as 5-digit serial numbers. Convert text dates using DATEVALUE() or by using Data > Text to Columns.

DATEDIF does not appear in autocomplete

This is normal — DATEDIF is a hidden compatibility function. You must type the full formula manually. It will work correctly once entered even though Excel does not suggest it.

Result looks like a date instead of a number

Excel has auto-formatted the result cell as a date. Press Ctrl+1, select Number from the category list, and set decimal places to 0. The result will then display as a plain integer.

Avoid "MD" in production files: Microsoft acknowledges that DATEDIF with the "MD" unit can return inaccurate results for certain date combinations, particularly near month-end dates. For the day portion of a full "years, months, days" string, use =B2-DATE(YEAR(B2),MONTH(B2),1) as a reliable alternative.

Frequently Asked Questions

  • What does DATEDIF do in Excel?+
    DATEDIF calculates the difference between two dates in a unit you specify — complete years, complete months, or total days. It also supports three "remainder" units (YM, YD, MD) for building combined strings like "3 years, 4 months, 12 days". It is available in all Excel versions but does not appear in autocomplete.
  • Why is DATEDIF not showing in Excel autocomplete?+
    DATEDIF is a hidden compatibility function inherited from Lotus 1-2-3. Microsoft intentionally omits it from the autocomplete list and function wizard. It works correctly when typed in full — simply type =DATEDIF( and fill in the three arguments manually.
  • How do I calculate age in Excel using DATEDIF?+
    Use =DATEDIF(DOB, TODAY(), "Y") where DOB is the date of birth cell. The "Y" unit returns complete years only, correctly accounting for whether the birthday has passed this year. The result updates automatically each day.
  • What is the difference between "M" and "YM" in DATEDIF?+
    "M" returns the total number of complete months between the two dates. "YM" returns only the remaining months after complete years have been counted. For example, between 1-Jan-2024 and 28-Mar-2026: "M" returns 26 (total months), while "YM" returns 2 (the 2 months left after 2 complete years).
  • Can DATEDIF calculate tenure automatically?+
    Yes. Use =DATEDIF(hire_date, TODAY(), "Y") for years of service, or combine "Y" and "YM" with the ampersand operator to get a "X years, Y months" string. Using TODAY() means the tenure value updates every time the workbook opens.
  • Why should I avoid the "MD" unit in DATEDIF?+
    Microsoft's own documentation acknowledges that the "MD" unit can produce incorrect results for certain date combinations, especially near the end of months. For the day portion of a combined date string, a safer approach is to subtract the start of the current month from the end date using =end_date - DATE(YEAR(end_date), MONTH(end_date), 1).