
Calculate completed years, months, or days between two dates. DATEDIF is useful when you need full units instead of rough date subtraction.
The DATEDIF function calculates the difference between two dates in completed years, months, or days. That word completed matters. DATEDIF does not estimate. It counts only full units that have actually been reached.
This is why DATEDIF is useful in age calculations, employee tenure, subscription length, and project tracking. If someone has not reached the next anniversary yet, DATEDIF will not count that next year or month early.
Use DATEDIF when you need full years, months, or days rather than simple date subtraction.
DATEDIF returns an integer. It does not return partial years or partial months.
=DATEDIF(start_date, end_date, "unit")
DATEDIF needs a start date, an end date, and a quoted unit code such as "y" or "m". One useful detail is that DATEDIF usually does not appear in Excel's autocomplete list, so you often need to type it manually.
The function also expects the start date to be earlier than the end date. If the dates are reversed, Excel can return a #NUM! error.
The most common unit codes are:
"y" for completed years"m" for completed months"d" for total days"ym" for leftover months after full years"yd" for leftover days after full years"md" for leftover days after full monthsDATEDIF is not the only way to compare dates, so it helps to know why you would use it instead of direct subtraction or another date function.
| Method | Main Result | Best For | Example |
|---|---|---|---|
DATEDIF |
Completed units | Age, tenure, and full-month or full-year calculations | =DATEDIF(A1,B1,"y") |
B1-A1 |
Raw day difference | Simple elapsed-day calculations | =B1-A1 |
DAYS |
Total days | Explicit day-based calculations | =DAYS(B1,A1) |
YEARFRAC |
Fractional years | Prorated calculations and partial-year math | =YEARFRAC(A1,B1) |
The main distinction is that DATEDIF is designed for completed intervals, not approximate ones.
The easiest way to understand DATEDIF is to think about anniversaries. If someone started on January 1, 2020 and today is December 31, 2025, they have not yet completed six full years. DATEDIF with the "y" unit will still return 5 until the next anniversary is reached.
This makes the function especially useful in HR and reporting work, where counting a full unit too early can cause a real logic problem.
"y" when you need completed years."m" when you need total full months."ym" when you want leftover months after counting full years.One caution is the "md" unit. It exists, but it is often treated carefully because it can be less intuitive in month-end situations. For high-stakes calculations, many people prefer to rely more on "y", "m", and "ym".
Use the "y" unit when you want the number of fully completed years between two dates.
=DATEDIF(A1,B1,"y")
This is useful for age, work tenure, or any calculation based on full anniversaries.
Calculate the number of full years between A1 and B1 with the "y" unit. Formula: =DATEDIF(A1,B1,"y").
Use the "m" unit when you want the total number of completed months in the entire span.
=DATEDIF(A1,B1,"m")
This is useful for subscriptions, contracts, and billing periods.
Calculate the total number of full months in the date range with the "m" unit. Formula: =DATEDIF(A1,B1,"m").
Use the "ym" unit when you want only the extra months after counting full years.
=DATEDIF(A1,B1,"ym")
This is useful when you want to write a result like "5 years, 3 months" instead of just total months.
Return the leftover months after full years with the "ym" unit. Formula: =DATEDIF(A1,B1,"ym").
You can combine DATEDIF with TODAY() to create a live result that updates automatically.
=DATEDIF(A1,TODAY(),"y")
This is a common pattern for age and seniority calculations.
Calculate completed years from A1 to today. Formula: =DATEDIF(A1,TODAY(),"y").
DATEDIF is most useful when you care about completed time units, not rough date differences. Once you understand the unit codes and the idea of full anniversaries, it becomes much easier to choose the right interval for age, tenure, and reporting logic.
DATEDIF returns completed years, months, or days between two dates."y", "m", and "ym" are the most common."md" unit can be less reliable in some scenarios.TODAY() for live age or service calculations.Tell your friends about this post