
The DATEDIF function in Excel calculates the difference between two dates in years, months, or days. The name DATEDIF stands for Date + Difference, meaning it calculates the difference between two dates. You must need to enter the unit for returning the values otherwise this function will return #NUM! error in the cell.
Objective |
Value Returned by function |
---|---|
Aim to get the difference between the two dates. |
DATEDIF Function will return a valid numeric values in the form of days, months, years. |
=DATEDIF(starting_date,ending_date,"unit") // Unit must be added compulsory.
Unit |
Explanation |
---|---|
y |
This unit returns the difference in complete years between the two dates. |
m |
This unit returns the difference in complete months between the two dates. |
d |
This unit returns the difference in complete days between the two dates. |
md |
Returns the difference in days but the function ignores both month and years |
ym |
Returns the difference in months but the function ignores both days and years |
yd |
Returns the difference in days but the function ignores years |
The formulas below explains how to use the DATEDIF function to calculate the total years, months, and days between April 1, 2021 (01-04-2021) and March 30, 2025 (30-03-2025).
The formulas remain the same, except for the unit used:
=DATEDIF(B4,C4,"y") // Formula returns the complete year as 3
=DATEDIF(B4,C4,"m") // Formula returns the complete months as 47
=DATEDIF(B4,C4,"d") // Formula returns the complete days as 1459
The explanations of results from the above formula are,
The below example formula will explains you how to use the DATEDIF function to find the followings:
=DATEDIF(B4,C4,"d") //Returns the value 1459 as days
=DATEDIF(B5,C5,"yd") //Returns the value 335, ignores years
=DATEDIF(B6,C6,"md") //Returns the value 30, ignores both years and months
For finding the difference in months, you can only use two units and they are “m, ym“
The formulas used to explain the working of finding the differences in month in the above image are,
=DATEDIF(B4,C4,"m") //Returns the months as 47
=DATEDIF(B5,C5,"ym") //Returns the months as 11, ignores years
The 1st formula returns the value as 47 for the dates between 01-04-2021 and 30-03-2025, which is absolutely correct.
The 2nd formula returns the value as 11 for the dates between 01-04-2023 and 01-03-2025, which is also correct. The DATEDIF function roundoffs to the nearest complete year. In this case, it calculates the difference in months after accounting for full years and ignores the extra 11 months since they do not form a complete year.
For finding the difference in months, you can only use one unit and which is “y”.
The formula used in the above image is,
=DATEDIF(B4,C4,"y") //Returns the value 5
=DATEDIF(B5,C5,"y") //Returns the value 4
The first formula returns 5 years for the dates between April 1, 2020 (01-04-2020) and August 30, 2025 (30-08-2025), which is correct. The total number of completed years between these two dates is 5.
For the second formula, the DATEDIF function returns 4 years because the ending date is February 1, 2025 (01-02-2025). Since two more months are needed to complete another full year, DATEDIF ignores the incomplete year and returns the last fully completed year count as 4.
You can other excel functions, to find the differences between the two dates in the form of years. Some of them are:
=INT(YEARFRAC(B4, C4, 1)) // Returns the Differences in years
=YEAR(C4) - YEAR(B4) - IF(DATE(YEAR(C4), MONTH(B4), DAY(B4)) > C4, 1, 0)
This function will ensures a correct year difference by considering end-of-month dates. It will adjusts the year count if the starting date hasn’t occurred yet.
=YEAR(C4) - YEAR(B4) - IF(EOMONTH(B4, 0) > C4, 1, 0) //Returns 5
=YEAR(C5) - YEAR(B5) - IF(EOMONTH(B5, 0) > C5, 1, 0) //Also Returns 5
The EOMONTH Function will consider the end of the month between the starting date and the ending date. As a result, the 2nd formula returns 5 years, even though the difference between the two dates does not end with a fully completed year.
To do this, you may need to adjust the formula with words to display the number with pretty form.
=DATEDIF(B4, C4, "Y") & " Years, " & DATEDIF(B4, C4, "YM") & " Months, " & DATEDIF(B4, C4, "YD") & " Days"
The above formula returns as 5 Years, 4 Months, 151 Days
By adjust the DATEDIF formula, you can easily print the difference between the two dates with words as shown in the above image.
By using the YEAR function, you can calculate the difference in years between two dates. However, it does not return the exact number of completed years. Instead, it gives the full difference between the years of the two dates.
=YEAR(C4) - YEAR(B4)
As you can see in the above image, the formula returns the full difference between the given years.
You can use the DATEDIF function to calculate age from birthday. I wrote a detailed article explaining the multiple formula to calculate the age from date of birth.
=DATEDIF(C4, TODAY(), "Y") //Return the AGE from the birthday.
You can use the above formula to calculate the accurate age from the given birthday using the DATEDIF function in the formula.
That’s it.