DATEDIF() function

This article explains how to use the DATEDIF() function

The DATEDIF() function is a useful utility for easily calculating the time difference between two dates (a period).

The syntax for the DATEDIF() function is as follows

DATEDIF(date1, date2, timeframe)
  • date1 is the starting date of the period
  • date2 is the ending date of the period
  • timeframe a letter code representing the type of difference

Where timeframe can be any of the following codes.

  • D gets the number of complete days in the period
  • M gets the number of complete months in the period
  • Y gets the number of complete years in the period
  • MD gets the difference in days disregarding months and years
  • YM gets the difference in months, disregarding days and years
  • YD gets the difference in days, disregarding months

NOTE: timeframe is not case sensitive.


DATEDIF(01/01/2001, 01/01/2002, "D") = 365 DATEDIF(01/01/2001, 01/01/2002, "M") = 12 DATEDIF(01/01/2001, 01/01/2002, "Y") = 1 DATEDIF(01/01/2001, 30/06/2002, "MD") = 29 DATEDIF(01/01/2001, 30/06/2002, "YM") = 5 DATEDIF(01/01/2001, 30/06/2002, "YD") = 180

Related articles

Learn more about datedif in one of the following articles