Happy Friday Excellers. Welcome back to another **#FormulaFriday #**Excel blog post in my 2020 Excel series. Today I want to share with you an old function in Excel that you can’t really find any help on recently. BUT, it’s a great one. It will help you to find the difference between two dates in a number of different variables such as years, months, days, hours etc. The function is **DATEDIF.**

### What Does DATEDIF Mean?.

So, this 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 for example.

### DATEDIF Syntax.

The syntax of the function is a follows.

=DATEDIF(Date1, Date2, Interval),

Where

** Date1** is the first date, **Date2** is the second date and the Interval is the interval type to return.

There are a few different codes you can use for the Interval and a summary can be seen below,

Let’s work through an example see how it works.

### Calculating The Length Of Service For An Employee (in years).

First, type A1 type 01/12/1990 in cell A1. Next, type 15/11/2010 in the cell B1. These are the first and second arguments in our function. In cell A4 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

M=239

D=7289

Y=19

YM=11

YD=349

MD=14

### Add More Detail To The Difference Between Two Dates.

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 example 0 Years, 11 Months and 14 Days then you might want to suppress your zeros so you get the result 11 Months and 14 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”**

### Notes On The DATEDIF Function.

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 be left without the “” double-quotes.

**If you want more Excel and VBA tips then sign up to my monthly Newsletter where I share 3 Excel Tips on the first Wednesday of the month and receive my free Ebook, 30 Excel Tips.**

**Likewise, if you want to see all of the blog posts in the Formula Friday Series Click The Link Below**

### How To Excel At Excel – Formula Friday

**So, Don’t forget to SUBSCRIBE to the How To Excel At Excel Newsletter for more tips the first Wednesday of the month.**

tamie says

this did not work for me, can you help?

I am working on cemetery records where i have the date of birth and the date of death and i want it to calculate how many years, months, and days this person lived

birth death age

c6 d6 = e6

9/4/1855 12/30/1939

I tried

=datedif(c6,d6,"Y"),(c6,d6,"YM"),(c6,d6,"MD) and so many others. i just don’t get it.

Barbara says

Tamie

You have a good point, dates before 1900 do not exist in Excel world! hence you are getting the error. You can follow the link to Microsoft’s site where they have a specific macro to help.

http://support.microsoft.com/?kbid=245104

OR

John Walkenbach has an Excel Add In

http://j-walk.com/ss/excel/files/xdate.htm

Regards

Barbara

Yasmeen says

In Excel 2010 the DATEDIF Formula why not working with the dates which entered in different column?

Barbara says

Hi Yasmeen

The DATEDIF should work equally well in Excel 2010, it does not however appearin the functions list you just have to manually type the formula.

Regards

Barbara

Melinda says

DATEDIF is not working in Excel2010 for me either. I know it works in other versions as I have used it before. Very strange.

Barbara says

Hello Melinda all should be good with the DATEDIF even in Excel 2010, can you post your formula?

Jewel says

Date of join 23/12/2015 and date of leave 6/1/2016

after implement above formula its showing total service length is 1 month 128 days

please advice

Barbara says

Hello

I have replicated your formula with the above dates. With the formula

=DATEDIF(A1,A2,”D”) gives result of 14.

Where A1 and A2 contain your fist and second date respectively.

If you still get the spurious result send me copy of your work book.

Thanks

Barbara

ctsondemand.com says

Use the DATEDIF function when you want to calculate the difference between two dates.

Manoj Kumar says

DATEDIF is not actual difference

01-05-1998

31-05-2032

=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"