The DATEDIF function computes the difference between two dates in a variety of different intervals,
such as the number of years, months, or days between the dates. This function is available in all
versions of Excel since at least version 5/95, but is documented in the help file only for Excel 2000. For
some reason, Microsoft has decided not to document this function in any other versions. DATEDIF is
treated as the drunk cousin of the Formula family. Excel knows it lives a happy and useful life, but will
not speak of it in polite conversation. Do not confuse the DATEDIF worksheet function with the
DateDiff VBA function.
The syntax for DATEDIF is as follows:
=DATEDIF(Date1, Date2, Interval)
Where:
Date1 is the first date,
Date2 is the second date,
Interval is the interval type to return.
If Date1 is later than Date2, DATEDIF will return a #NUM! error. If either Date1 or Date2 is not a valid
date, DATEDIFwill return a #VALUE error.
The Interval value should be one of
Interval
m
Meaning
Months
Days
Years
ym
Months
Excludin
g Years
Days
Excludin
g Years
Days
Excludin
g Years
And
Months
yd
md
If
Description
Complete calendar months
between the dates.
Number of days between the
dates.
Complete calendar years
between the dates.
Complete calendar months
between the dates as if they
were of the same year.
Complete calendar days
between the dates as if they
were of the same year.
Complete calendar days
between the dates as if they
were of the same month and
same year.
Interval is not one of the items listed in above, DATEDIF will return a #NUM error.
Interval string directly within the formula, you must enclose it in double quotes:
=DATEDIF(Date1,Date2,"m")
If you have the interval in another cell referenced by the formula, that cell should not have quotes around the interval string. For example, with the formula
=DATEDIF(Date1,Date2,A1)
cell
Examples
The follow are some examples of the DATEDIF function.
Date1: 1-Jan-2007
Date2: 10-Jan-2007
Interval: d
Result: 9
Explanation:
There are 9, not 10, calendar days between these two dates.
Date1: 1-Jan-2007
Date2: 31-Jan-2007
Interval: m
Result: 0
Explanation:
There 0 complete calendar months between the two dates.
Date1: 1-Jan-2007
Date2: 1-Feb-2007
Interval: m
Result: 1
Explanation:
There are 1 complete months between the two dates.
Date1: 1-Jan-2007
Date2: 28-Feb-2007
Interval: m
Result: 1
Explanation:
There are 1 complete months between the two dates.
Date1: 1-Jan-2007
Date2: 31-Dec-2007
Interval: d
Result: 364
Explanation:
There are 364 days between the two dates.
Date1: 1-Jan-2007
Date2: 31-Jan-2007
Interval: y
Result: 0
Explanation:
There are 0 complete years between the dates
Date1: 1-Jan-2007
Date2: 1-July-2008
Interval: d
Result: 547
Explanation:
There are 547 days between the two dates.
Date1: 1-Jan-2007
Date2: 1-July-2008
Interval: m
Result: 18
Explanation:
There are 18 months between the two dates.
Date1: 1-Jan-2007
Date2: 1-July-2008
Interval: ym
Result: 6
Explanation:
There are 6 months between the two dates if the dates are considered to have the same year. The year
it taken fromDate1, not Date2. This makes a difference when one year is a leap year. Since 2007 is
not a leap year, 29-Feb is not counted. See DATEDIF And Leap Years below.
Date1: 1-Jan-2007
Date2: 1-July-2008
Interval: yd
Result: 181
Explanation:
There are 181 days between the dates if the dates are considered to have the same year. The year it
taken from Date1, not Date2. This makes a difference when one year is a leap year. Since 2007 is not
a leap year, 29-Feb is not counted. See DATEDIF And Leap Years below.
Date1: 1-Jan-2008
Date2: 1-July-2009
Interval: yd
Result: 182
Explanation:
There are 182 days between the dates if the dates are considered to have the same year. This result is
182 not 181 sinceDate1 is a leap year and thus 29-Feb is counted.
Date1: 1-Jan-2007
Date2: 31-Jan-2007
Interval: md
Result: 30
Explanation:
There are 30 days between the 1st and 31st of the dates when both dates' month and years are
considered to be the same.
Calculating Age
You can use the DATEDIF to calculate a person's age. For example, the formula below will calculate the
age of a person as of the current date, where BirthDate is the person's date of birth.
=DATEDIF(BirthDate,TODAY(),"y")&" years"& DATEDIF(BirthDate,TODAY(),"ym")&
"months" & DATEDIF(BirthDate,TODAY(),"md")&" days"
http://www.cpearson.com/excel/datedif.aspx