What DATEDIF does

DATEDIF counts the complete years, months or days between two dates. =DATEDIF(B4,$B$1,"y") gives the whole years from the date of birth in B4 to the date in B1, which is how you calculate an age in Excel. A year counts only once its anniversary has arrived, so someone whose birthday is tomorrow is still the younger age today.

That rule makes it the function for ages and length of service. Dividing the days by 365 comes close but drifts, because every leap year adds a day, and an age worked out that way can go up a day or two before the birthday.

Excel keeps DATEDIF so that workbooks made in Lotus 1-2-3, an older spreadsheet program, still calculate. It doesn’t appear in Insert Function or in the suggestions while you type, but it calculates when you type the whole name.

Syntax

=DATEDIF(start_date, end_date, unit)
Every argument is required.
start_dateRequired
The earlier date, such as a date of birth or a hire date in B4. If it comes after end_date, DATEDIF returns #NUM!.
end_dateRequired
The later date: a report date in a cell such as $B$1, or TODAY() to count up to today.
unitRequired
What to count, in quotation marks. "y" counts complete years, "m" complete months and "d" days. "ym" gives the months left over after the complete years. Microsoft advises against "md", which can give wrong results.

The unit decides what DATEDIF counts. For a period from Sep 23, 2019 to Mar 2, 2026:

UnitWhat it countsResult
"y"Complete years6
"m"Complete months77
"d"Days2,352
"ym"Months left over after the complete years5

Capital letters work too, so "Y" gives the same 6. Two more units, "md" and "yd", ignore the months or the years of the dates. Microsoft warns that "md" can return a negative number, a zero or a wrong result, and the FAQ below has a safer way to count the leftover days.

Example: an age from a date of birth

An HR report shows each person’s age on the report date in B1. In a live sheet B1 could hold =TODAY(). Here it’s fixed at Nov 30, 2026, so the example shows the same ages on any day.

Ben turns 38 on Dec 2, after the report date, so he's still 37. Cleo's birthday falls on the report date, and it counts. In C4, =DATEDIF(B4,$B$1,"y") returns 35.

Read it as: count the complete years from B4 to B1. The dollar signs lock B1, so every row measures up to the same report date when you fill the formula down.

Example: years and months of service

A leavers’ report shows each person’s service as years and months, such as 6 yr 5 mo. One DATEDIF with "y" gives the complete years, a second with "ym" gives the months after them, and & joins the two with the labels.

Lena left one day before her third anniversary, so her service is 2 complete years and 11 months. In D2, =DATEDIF(B2,C2,"y")&" yr "&DATEDIF(B2,C2,"ym")&" mo" returns 6 yr 5 mo.

For the service in months alone, use "m": Rosa’s 6 years and 5 months are 77 months.

Common mistakes

  • =DATEDIF($B$1,B4,"y"), with the dates the wrong way round, returns #NUM!. The earlier date always goes first.
  • =YEAR(C2)-YEAR(B2) subtracts the years and ignores the day and month. For someone who started on Oct 5, 2020, it gives 6 on Mar 2, 2026, where DATEDIF gives the correct 5.
  • =INT((C2-B2)/365) drifts because of leap days. For a date of birth of Jun 1, 2000, it gives 26 on May 30, 2026, two days before the 26th birthday. DATEDIF gives 25.
  • =DATEDIF(B2,C2,y), without quotation marks around the unit, makes Excel look for something named y. The unit is text and always goes in quotes.
  • A date that stayed text when it was typed, such as 30.11.2026 in a US workbook, gives #VALUE!. Retype it as a date or build it with DATE.

Frequently asked questions

How do I calculate age in Excel?

With the date of birth in B2, =DATEDIF(B2,TODAY(),"y") gives the age in complete years. It goes up by one on the birthday itself, and TODAY keeps it current every day.

Why can't I find DATEDIF in Excel?

Excel keeps DATEDIF for older workbooks and leaves it out of Insert Function and the suggestions that appear as you type. Type the whole formula, such as =DATEDIF(B2,C2,"y"), and it calculates.

Why does DATEDIF return #NUM!?

The start date is later than the end date. Put the earlier date first. If either cell can hold the earlier date, sort them inside the formula: =DATEDIF(MIN(B2,C2),MAX(B2,C2),"y").

How do I get the years, months and days between two dates?

Use "y" for the years and "ym" for the months after them. For the days after the last complete month, =C2-EDATE(B2,DATEDIF(B2,C2,"m")) counts them from the last monthly anniversary; format that cell as a number. Microsoft advises against the "md" unit for this, because it can give wrong results.

How do I count the days between two dates?

Subtract the earlier date from the later one, as in =C2-B2, or use =DATEDIF(B2,C2,"d"), which gives the same number. For working days only, use NETWORKDAYS.