Month Calculation

T

Tony

I would like to calcuate the diff in the dates by in term of months e.g.
30.06.05 less 19.11.04 = 8 months. What function should I use, could any one
help please. Thanks
 
D

Dave Thomas

There is an undocumented function in Excel called DATEDIF. Microsoft has
never documented it. It comes from Lotus 1-2-3.
It does not appear in the list of functions. You must manually type it in.
Its format is =DATEDIF(start_date,end_date,"F"). Note that start_date must
be less or equal to end_date or you will get a #NUM error.
F must be in quotes and may be the following:

"y" The number of complete years in the period
"m" The number of complete months in the period
"d" The number of days in the period.
"md" The difference between the days in start_date and
end_date. The months and years of the dates are ignored.
"ym" The difference between the months in start_date and
end_date. The days and years of the dates are ignored.
"yd" The difference between the days in start_date and
end_date. The years of the dates are ignored.

So if cell A1 has 30.06.05 and cell A2 has 19.11.04 then
=DATEDIF(A2,A1,"m") would return 7, the number of whole months difference
between those dates.
 
H

Harlan Grove

Dave Thomas said:
There is an undocumented function in Excel called DATEDIF. Microsoft has
never documented it. . . .

Bizarrely enough, Microsoft DID document it in Excel 2000, but neither in
previous nor subsequent versions.
. . . It comes from Lotus 1-2-3. . . .

Which could be said of 90% or more of Excel's functions.
 
J

joeu2004

I would like to calcuate the diff in the dates by in term of months
e.g. 30.06.05 less 19.11.04 = 8 months. What function should I
use, could any one help please.

As Dave pointed out, DATEDIF() alone does not give you the result you
want -- unless you misstated your requirement. The following might do
the trick for you:

=datedif(A1, A2, "m") +
or(day(A1)<day(A2), and(day(A1)>day(A2), A1=eomonth(A1,0),
A2=eomonth(A2,0)))

where A1 is the earlier date (e.g. 19.11.04) and A2 is the later date
(e.g. 30.06.05). The logic is: the difference in months, plus one
only if:

1. The earlier day is less than the later day (that is, more than an
exact number of months elapsed), as in your example. Or

2. The earlier day is greater than the later day, but both dates are
the end of the month. For example, the difference between 31.12.2004
and 28.2.2005 would be 2 months.
 
Top