DATEDIF (date difference)

<< Click to Display Table of Contents >>

DATEDIF (date difference)

Syntax:

DATEDIF(StartDate, EndDate, Mode)

Description:

Returns the number of days, months or years between two dates.

StartDate and EndDate are the two dates to be evaluated. StartDate must be less (i.e., earlier) than EndDate.

Mode lets you specify the kind of value to be returned:

"y"

Number of years between StartDate and EndDate

"m"

Number of months between StartDate and EndDate

"d"

Number of days between StartDate and EndDate

"ym"

Number of months, excluding years (as if StartDate and EndDate were in the same year)

"yd"

Number of days, excluding years (as if StartDate and EndDate were in the same year)

"md"

Number of months, excluding month and years (as if StartDate and EndDate were in the same month and year)

Note:

This function is an undocumented Excel function. It still exists in Microsoft Excel, but has been removed from Excel's help file and therefore seems to be no longer officially supported.

Example:

To calculate the age of a person, enter the date of birth in cell A1 (e.g. 4/3/1970). In A2, enter the current date (e.g. 6/8/2012).

Then, use any of the following calculations:

Age in years:

DATEDIF(A1, A2, "y") returns 42 (years)

Age in months:

DATEDIF(A1, A2, "m") returns 506 (months)

Age in days:

DATEDIF(A1, A2, "d") returns 15407 (days)

Age in years, months and days:

DATEDIF(A1, A2, "y") returns 42 (years)

DATEDIF(A1, A2, "ym") returns 2 (months)

DATEDIF(A1, A2, "md") returns 5 (days)

(Accordingly, the person's age is 42 years, 2 months and 5 days.)

See also:

NOW, NETWORKDAYS, DAYS/DAYSP