Skip to content

Calculate the Difference Between Dates

In this article, you will learn how to calculate the difference between dates using the DATEDIF function.

The DATEDIF function is available in both Microsoft Excel and Google Sheets, and it allows you to calculate the difference between two dates in the form of days, months, or years.

The DATEDIF Function

The DATEDIF function calculates the number of days, months, or years between two dates.

The DATEDIF function requires three arguments. These three arguments are:

  1. Start Date
  2. End Date
  3. Unit

The Start Date and the End Date are fairly straightforward arguments to understand. These arguments may be a hard-coded value (a value typed directly into the formula) or a reference to a cell containing a date.

Hard Coded

=DATEDIF(01/01/2022, 02/01/2022, unit)

References to Cells

=DATEDIF(A1, A2, unit)

The Unit Argument

The Unit argument is the key argument to this function. The Unit determines what metric the DATEDIF function will return.

For example, the DATEDIF function will return the difference in days if the Unit argument is set to “D.”

If the Unit is set to “M,” the DATEDIF function will return the difference in months.

The Unit argument may be set to any of the following:

  • D
  • M
  • Y
  • MD
  • YM
  • YD

You will learn how each argument affects the DATEDIF function.

Unit – D

When the Unit argument is set to D, the DATEDIF function will return the difference between the two dates in days.

Unit – M

When the Unit argument is set to M, the DATEDIF function will return the difference between the two dates in months.

Take note that the DATEDIF function will not count part of a month. It will only return how many full months are between two dates.

Unit – Y

When the Unit argument is set to Y, the DATEDIF function will return the difference between the two dates in years.

Take note that the DATEDIF function will not count part of a year. It will only return how many full years are between two dates.

Unit – MD

When the Unit argument is set to MD, the DATEDIF function will return the difference between the two dates in days while ignoring the month and year.

For example, let’s say the start date is January 1st, 2022 and the end date is February 2nd, 2023.

The DATEDIF function returns a value of because the year and month are ignored. All that’s left is the 2nd minus the 1st, which is equal to 1.

Unit – YM

When the Unit argument is set to YM, the DATEDIF function will return the difference between the two dates in months while ignoring the year.

For example, let’s say the start date is January 15th, 2022 and the end date is April 1st, 2023.

The DATEDIF function returns a value of because the year is ignored. All that’s left are January 15th and April 1st. There are only two full months between these dates, so the value of 2 is returned.

Unit – YD

When the Unit argument is set to YD, the DATEDIF function will return the difference between the two dates in days while ignoring the year.

For example, let’s say the start date is January 1st, 2022 and the end date is February 1st, 2023.

The DATEDIF function returns a value of 31 because the year is ignored. All that’s left are January 1st and February 1st, and there are 31 days between these two dates when disregarding the year.

And that’s how you can use the DATEDIF function to calculate the difference between two dates!

This Post Has One Comment

  1. Wow, who knew there were so many different inputs for the last argument of that function! I can’t wait to start experimenting with theses!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top