1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Calculate the Difference Between Two Dates in Excel

By

Excel DATEDIF Function
Excel Date Difference Function

Excel Date Difference Function

© Ted French

Note: If you are experienced using Excel functions try the Excel DATEDIF Function Text-only Tutorial which is a bare bones tutorial on the Date Difference function.

This tutorial is intended for users new to using Excel's date functions.

Calculate the Number of Days Between Two Dates in Excel

Excel has several built in date functions that can be used to calculate the number of days between two dates.

Each date function does a different job so that the results differ from one function to the next. Which one you use, therefore, depends on the results you want.

Excel Date Difference Function

The DATEDIF function can be used to calculate the time period or difference between two dates. This time period can be calculated as the number of days, months, or years between the two dates.

Uses for this function include planning or writing proposals to determine the time frame for an upcoming project. It can also be used, along with their birth date, to calculate a person's age in years, months, and days.

DATEDIF Function Undocumented

An interesting point about DATEDIF is that it is an "undocumented" function which means it is not listed with other Date functions under the formula tab in Excel.

To use DATEDIF you must type it manually into a cell on the worksheet rather than using the dialog box method available for other functions.

The DATEDIF Function's Syntax and Arguments

A function's syntax refers to the layout of the function and includes the function's name, brackets, and arguments.

The syntax for the DATEDIF function is:

= DATEDIF ( start_date , end_date , "interval")

The function has three arguments that need to be entered as part of the function:

Start_date - (required) the start date of the chosen time period. The actual start date can be entered for this argument or the cell reference to the location of this data in the worksheet can be entered instead.

End_date - (required) the end date of the chosen time period. As with the Start_date, enter the actual end date or the cell reference to the location of this data in the worksheet.

"Interval" - (required) tells the function to find the number of days ("D"), complete months ("M"), or complete years ("Y") between the two dates.

Note: When entering the Interval argument you must include the quotation marks such as "D".

More on the Interval Argument

The Interval argument can also contain a combination of days, months, and years in order to increase the variety of answers returned by the function.

  • "YM" - calculates the number of months between two dates as if the dates were in the same year
  • "YD" - calculates the number of days between two dates as if the dates were in the same year
  • "MD" - calculates the number of days between two dates as if the dates were in the same month and year

Example: Calculate the Difference Between Two Dates

For help with this example, see the image above.

Since the DATEDIF function can be used to find either the number of days, the number of months, or the number of years between two dates, this example will show separately how to calculate all three between the dates of July 9, 2010 and November 2, 2012.

Note: To avoid calculation problems that can occur if dates are accidentally entered as text, the DATE function will be used to enter the dates used in the function.

Also Note: When manually entering a function in Excel you must type a comma between each argument to act as a separator.

Entering the Data

  1. Enter the following data into the appropriate cell:

    D1 - Start Date:
    D2 - End Date:
    D3 - Difference (Days):
    D4 - Difference (Months):
    D5 - Difference (Years):
    E1 - =DATE(2010,7,9)
    E2 - =DATE(2012,11,2)

If the dates in cells E1 and E2 do not appear as shown in the image above, check to see that these cells are formatted to display data using the short date format.

Calculating the Difference in Days

  1. Click on cell E3 to make it the active cell - this is where the number of days between the two dates will be displayed

  2. Type " = datedif " in cell E3

  3. Type an opening round bracket " ( " after the function name

  4. Click on cell D1 to enter this cell reference as the Start_date argument for the function

  5. Type a comma ( , ) in cell E3 following the cell reference D1 to act as a separator between the first and second arguments

  6. Click on cell D2 in the spreadsheet to enter this cell reference as the End_date argument

  7. Type a second comma ( , ) following the cell reference D2 .

  8. For the Interval argument, type the letter D in quotes ("D" ) to tell the function we want to know the number of days between the two dates

  9. Type a closing bracket " ) "

  10. Press the ENTER key on the keyboard

  11. The number of days - 847 - should appear in cell E3 of the worksheet

  12. When you click on cell E3 the complete function =DATEDIF (E1, E2, "D") appears in the formula bar above the worksheet

Calculating the Difference in Complete Months

DATEDIF returns only the number of full or complete months between the two dates.

  1. In cell E4, repeat steps 2 - 7 above

  2. For the Interval argument, type the letter M in quotes ("M" ) in cell E4 after the second comma to tell the function we want to know the number of months between the two dates

  3. Type the closing bracket " ) "

  4. Press the ENTER key on the keyboard

  5. The number of complete months - 27 - should appear in cell E4 of the worksheet

  6. When you click on cell E4 the complete function =DATEDIF (E1, E2, "M") appears in the formula bar above the worksheet

Calculating the Difference in Complete Years

DATEDIF returns only the number of full or complete years between the two dates.

  1. In cell E5, repeat steps 2 - 7 of the Difference in Days Example above

  2. For the Interval argument, type the letter Y in quotes ("Y" ) in cell E5 after the second comma to tell the function we want to know the number of years between the two dates

  3. Type the closing bracket " ) "

  4. Press the ENTER key on the keyboard

  5. The number of complete years - 2 - should appear in cell E5 of the worksheet

  6. When you click on cell E5 the complete function =DATEDIF (E1, E2, "M") appears in the formula bar above the worksheet

DATEDIF Function Error Values

If the data for the various arguments of this function are not entered correctly the following error values appear in the cell where the DATEDIF function is located:

  • #VALUE! : appears in the answer cell If one of DATEDIF 's arguments is not a valid date (if the date was entered as text for example)
  • #NUM!: appears in the answer cell if the Start_date is larger (later in the year) than the End_date argument

©2014 About.com. All rights reserved.