This is an old function in Excel that you can’t really find any help on recently , but its a great one, to find the difference between two dates in a number of different variables such as years, months, days, hours etc.
The function actually stands for Date Difference and is really useful for calculating employees age, length of service of an employee or the length of a loan etc.
The way to use this function is
=DATEDIF(Date1, Date2, Interval), where Date1 is the first date, Date2 is the second date and the Interval is the interval type to return.
As usual it’s way easier with an examples.
1. Let’s calculate the length of service for an employee in years.
In cell A1 type 01/12/1990
In cell A2 type 15/11/2010
In cell A5 type your formula DATEDIF(A1,A2,”Y”), this should give you an answer of 19.
Go ahead and try the rest of the intervals, the answers you should get can be seen below
Now, this all may look at little too literal, and it usually is the case that for payroll or length of service you would want to know then years, months and days a person has worked, that of course can be done in Excel just by turning up the volume on the formula.
So, if we use the same example that we want to find out the years, months and days that someone had worked for a company for payroll reasons then your formula would look like this.
DATEDIF(A1,A2,”y”)&” years “&DATEDIF(A1,A2,”ym”)&” months “&DATEDIF(A1,A2,”md”)&” Days”
The result in this instance would be 19 Years, 11 Months and 14 Days. However, if your result of the formula contains a zero for exmaple
0 Years, 14 Months and 2 Days then you might want to supress your zeros so you get the result 14 Months and 2 Days only. Again with a little tweaking of the formula we can achieve this by adding in a sneaky IF statement and your formula would look like this:-
=IF(DATEDIF(A1,A2,”y”)=0,””,DATEDIF(A1,A2,”y”)&” years “)&IF(DATEDIF(A1,A2,”ym”)=0,””,
DATEDIF(A1,A2,”ym”)&” months “)&DATEDIF(A1,A2,”md”)&” days”
If the interval is typed into the formula then as it is a string, it needs to be set in “” double quotes, if it is referred to in a cell reference there is no need and can left without the “” double quotes.