ShareYourGroupShareYourGroupExcel Formulas

Date and time functions

DATEDIF function in Excel

DATEDIF returns the number of complete years, months or days between two dates.

How old is someone? How long has an employee served? How many months has a loan been running? Subtracting two dates gives days, and turning days into years by dividing by 365 is slightly wrong because of leap years. DATEDIF counts completed years and months the way people do.

Syntax

=DATEDIF(start_date, end_date, unit)
ArgumentWhat it is
start_dateThe earlier date.
end_dateThe later date.
unit"Y" complete years, "M" complete months, "D" days, "YM" months left after the complete years, "MD" days left after the complete months, "YD" days left after the complete years.

Examples

Each result below is what Excel itself showed for the formula on the sample sheet.

Sample sheet: Staff with their date of birth and date of joining, and a short list of holidays.
ABCD
1NameBornJoinedHoliday
2Anita19-Jul-198801-Apr-201926-Jan-2026
3Rohit30-Nov-199215-Jun-202004-Mar-2026
4Deepa29-Feb-199601-Sep-202115-Aug-2026
5Manoj05-Dec-199910-Jan-202202-Oct-2026

A function Excel does not advertise

DATEDIF does not appear in Excel's list of functions, and nothing pops up to help when you type it. It has been kept for compatibility with older spreadsheet programs. It works in every version. You must type the name and all three arguments yourself.

The units

UnitCountsExample: 1 Apr 2019 to 12 Nov 2026
"Y"complete years7
"M"complete months91
"D"days2782
"YM"months beyond the complete years7
"MD"days beyond the complete months11
"YD"days beyond the complete years225

"Complete" is the key word. A year counts only once the anniversary has arrived. That is why Rohit, whose birthday is at the end of November, is one year younger on 12 November than a rough calculation would say.

Age

With the date of birth in B2:

=DATEDIF(B2, TODAY(), "Y")

The age goes up by one on each birthday, with no further work. For an age on a particular day, such as the cut-off date of an examination or a school admission, put that date in place of TODAY.

Years, months and days together, as some forms ask:

=DATEDIF(B2,TODAY(),"Y")&" years "&DATEDIF(B2,TODAY(),"YM")&" months "&DATEDIF(B2,TODAY(),"MD")&" days"

Length of service

The same formulas with the date of joining give service in years and months, as in the sixth example. Gratuity, leave entitlement and increments often depend on completed years, which is exactly what "Y" counts.

The earlier date goes first

If the start date is later than the end date, the result is #NUM!, as the last example shows. Excel does not swap them for you. When either order is possible, wrap the dates: =DATEDIF(MIN(A2,B2),MAX(A2,B2),"D").

A known fault in "MD"

Microsoft's own documentation warns that the "MD" unit can give a wrong result, even a negative number, for some pairs of dates, typically when the start day is late in a month and the end month is shorter. If you need the leftover days and they must be right, work them out another way: =end - EDATE(start, DATEDIF(start, end, "M")). This subtracts the date that lies exactly the completed months after the start.

Alternatives

Common mistakes

In Google Sheets

DATEDIF is a documented, ordinary function in Google Sheets, with the same six units.

Related functions

Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.

This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.