Difference between 2 dates – DATEDIF


Calculate the difference between 2 dates is not an easy task in Excel.

You must take in consideration if you want to return a result based on the gap of the months or based of the years, or both.

What is the problem?

Let's suppose that you have these 2 dates

  • 28/07/2017
  • 05/08/2017

The result between this 2 dates is 9 days. But the months are not the same.

So if we use the MONTH function, the result is 1 and it's  wrong, wrong, WRONG!


DATEDIF is not visible

The previous example showed that a difference between 2 dates is NEVER an easy calculation.

But also, how do we want to return the result?

  • By year?
  • By month?
  • Or by month in a year?

To perform all these calculations, Excel has an incredible function to realize all the different calculation between 2 dates. It is the DATEDIF function.

Unfortunately, this function is hidden (wh ... what ???) 😲😲😲

To find out, open the help for this function. You won't see it in the list of function but it works perfectly (they're weird at Microsoft ????)

The DATEDIF function is not listed in the dialog box

The DATEDIF function

This function requires 3 arguments:

  • The first date
  • Second date (necessarily greater than the first date)
  • The type of calculation


Results return by each parameter of the DATEDIF function

The third parameter of the function (the most important)

The first 3 codes are easy to understand

  • d (day) calculates the difference in number of days between the 2 dates.
  • m (month) calculates the difference in number of months
  • y (year) calculates the difference in number of years

The other codes return a value within month or day limits

  • ym will return the number of months inside a year. Possible value between 0 and 11.
  • md will return a value between 0 and 30.
  • yd is less useful. This code returns the number of days in a year. Possible value between 0 and 364.

Calculate the seniority

In column B, we have the hiring dates of our employees. The second date is the current date returned by the TODAY function.

Seniority of the employees calculated with DATEDIF
Calculate the age of each employees

For each columns, we have the following formulas

  • For the years


  • For the months inside a year


  • For the days inside a month


Related posts

Permanent link to this article: https://www.excel-exercise.com/difference-between-2-dates-datedif/

Leave a Reply

Your email address will not be published.