How to Use Datediff in Excel

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

The "DateDiff" function in Excel lets you display the difference between two dates. The difference can be in days, years or months. The result shows in the cell where you type the equation into the Excel spreadsheet, and is displayed in an integer format next to the dates you want to evaluate.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Click the Windows "Start" button and select "All Programs." Click "Microsoft Office," then click "Microsoft Excel" to start the program.

  2. 2

    Press the "Ctrl" and "O" keys on the computer. In the opened dialogue window, double-click the file you want to edit. Click the cell where you want the results of the "DateDiff" function to appear.

  3. 3

    Click the "Developer" ribbon tab at the top of the Excel window. Click the "Visual Basic" button to open the VBA editor. Double-click "Sheet1" to open the editor to the current sheet.

  4. 4

    Type the following code in the editor:

    Function GetDifference (myDate1 as Date, myDate2 as Date) as Long

     GetDifference = DateDiff("d", myDate1, myDate2)
    

    End Function

  5. 5

    Click the "Save" button, then close the VBA editor. Type "=GetDifference(A2, A1)" and press "Enter." Replace "A2" and "A1" with the cells that contain the dates you want to compare. Excel calls the VBA function and displays the date difference in days.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.