# The DATEDIF Function

The DATEDIF function is a worksheet function that computes the difference between two dates. This function is available in all versions of Excel since version 5, but is documented onl in the help files for Excel !""". It isn#t documented in either Excel \$% or Excel !""!. DATEDIF has, for whatever reason, been treated as one of the drunk cousins of the Function Famil . Excel knows he lives a happ and useful existence, and will acknowled&e his existence when ou ask, but will never mention him in 'polite' conversation. (ou can use DATEDIF as ou would an normal worksheet function, because it is a normal worksheet function. )ntil Excel!""", it was never documented in the help files, but it has been around since at least Excel5. There has been, from time to time, an article in the *nowled&e +ase describin& DATEDIF, but as often as not, the article is not available. ,h - ,ho knows- .ne of the deep dark secrets known onl the /ofties. The s ntax for DATEDIF is as follows0 =DATEDIF(Date1,Date2,Interval) ,here Date1 is the first date, in standard Excel serial1date format. Date2 is the second date, in standard Excel serial1date format. Interval indicates the unit of time that =DATEDIF is to return is result. Date1 must be less than 2earlier3 or e4ual to Date2. .therwise, =DATEDIF will return a #NUM! error. If either Date1 or Date2 is not a date, =DATEDIF will return a #VALUE! error. Interval must be one of the followin& codes0 Code "m" "d "y" "ym" "yd" Meaning 5onths Days (ears Description The number of complete months between Date6 and Date!. The number of da s between Date6 and Date!. The number of complete ears between Date6 and Date!.

5onths Excludin& The number of months between Date6 and Date!, (ear as if Date6 and Date! were in the same ear. Da s Excludin& (ears The number of da s between Date6 and Date!, as if Date6 and Date! were in the same ear.

The number of da s between Date6 and Date!, as Da s Excludin& "md" if Date6 and Date! were in the same month and the 5onths And (ears same ear.

When passing the interval code to the DATEDIF function, enclose it in quotes if you are passing a literal value to the function:
=DATEDIF(A1,NOW(),"d")

However, if your interval code is stored in a worksheet cell, it should not be

and ' d' interval ar&uments that DATEDIF does.NOW(). m!nt"s. .M!nt"(Date1) . To compute a&e in .(12 0 (Tem.1 / Date2) M = M!nt"(Date2) .1 D = Day(Date*er&al(+ear(date2)."ym") & " months.1 / Date2)) D = Day(Date2) .NOW()."md") & " days" This will return a strin& like 33 years.NOW(). The formula below will return someone#s exact a&e based on their birthda in cell A6. The same is true with the md interval. ou have to do the math on our own.1 As Date Tem. 3)) . =DATEDIF(A1. Day(Date1)) + = +ear(Date2) . M!nt"(Date1).1 = Date*er&al(+ear(Date2). " & DATEDIF(A1. 1# days (ou can#t use DATEDIF in . F\$n%t&!n A'e(Date1 As Date. " & DATEDIF(A1.+A provides a function called DateDiff 2note. . two f#s3.+A. The 5 indicates that there are 5 calendar months between 8anuar and 8une 11 the ears are i&nored. M!nt"(date2). 'md'. There are 69 calendar da s between the two dates when the months and ears are i&nored. Date2 As Date) As *tr&n' D&m + As Inte'er D&m M As Inte'er D&m D As Inte'er D&m Tem.+ear(Date1) . but DateDiff doesn#t support the ' m'. The table on the ri&ht displa s the results of the various interval codes for two dates.+A code. (Tem.enclosed in quotes in the cell."y") & " years. :alculatin& A 7erson#s A&e A fre4uent use of the DATEDIF is to compute someone#s a&e based on the current date and their birthda .Day(Date1) I1 D 2 3 T"en M = M . 7a attention to the result returned b the ym interval code.

Excel will use the ear of the first date. if Date6 is 61Feb16\$\$5 and Date! is 615ar16\$\$=. if Date6 is 61Feb16\$\$=. If Date6 is chan&ed to 61Feb16\$\$% and Date! remains 615ar16\$\$%. .Date2.hen ou are usin& the yd interval. it uses the ear of Date6 as the ear for both dates. and Date! is 615ar16\$\$%. the number of da s between 61Feb16\$\$% and 615ar16\$\$%. For example. the same function will return !>. =DATEDIF(Date1. /imilarl . the result is !> because both dates are &iven the ear of the first date. because there are !\$ da s between 61Feb16\$\$= and 615ar16\$\$=. to determine whether the to include !\$1Februar in the calculation. in these last two examples."yd") will return !\$.D End I1 A'e = + 4 " years " 4 M 4 " m!nt"s " 4 D 4 " days" End F\$n%t&!n DATEDIF And <eap (ears . In other words. is not a leap ear. Date6. which.