Professional Documents
Culture Documents
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")
(ou can#t use DATEDIF in ;+A code. ;+A provides a function called DateDiff 2note, two f#s3, but DateDiff doesn#t support the ' m', 'md', and ' d' interval ar&uments that DATEDIF does. To compute a&e in ;+A, ou have to do the math on our own. F$n%t&!n A'e(Date1 As Date, 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,1 As Date Tem,1 = Date*er&al(+ear(Date2), M!nt"(Date1), Day(Date1)) + = +ear(Date2) - +ear(Date1) . (Tem,1 / Date2) M = M!nt"(Date2) - M!nt"(Date1) - (12 0 (Tem,1 / Date2)) D = Day(Date2) - Day(Date1) I1 D 2 3 T"en M = M - 1 D = Day(Date*er&al(+ear(date2), M!nt"(date2), 3)) .
D End I1 A'e = + 4 " years " 4 M 4 " m!nt"s " 4 D 4 " days" End F$n%t&!n