Datediff & bissextile year
Hi all,
I was thinking the same way but if you really want to calculate the age of
persoon on a given date then this function is not correct for dates
(day/month) before the d.o.b..
datediff("yyyy",dateserial(1987,2,15),dateserial(2 000,2,15)) returns13
but
datediff("yyyy",dateserial(1987,2,15),dateserial(2 000,1,1)) returns also 13
however the age is still 12.
To be fully correct, you have to include a test on day & month and depending
on the result decrease datediff with 1.
if month_dob < month_given_date then
datediff
else ''' month_dob = month_given_date
if day_given_date < day_dob then
datediff-1
else
datediff
end if
end if
Wkr,
JP
"Jacob Skaria" wrote in message
...
Try
DateDiff("yyyy", Range("A1"),Range("B1"))
OR
ActiveCell.Offset(0, 1) = DateDiff("yyyy", ActiveCell.Offset(0, 0).Value,
Range("c2").Value)
With your code. Dont use Int() Instead try using Round
ActiveCell.Offset(0, 1) = Round(DateDiff("d", ActiveCell.Offset(0,
0).Value,
Range("c2").Value) / 365.25)
If this post helps click Yes
---------------
Jacob Skaria
"Basta1980" wrote:
Hi,
I have a list of employees in column A2 through to column A*. In Column
B2
through to Column B is their corresponding d.o.b. I have a code (used
from
other thread in this community) to retrieve age in years. This works
fine,
except for years leading upto a bissextile year. What happens is when I
have
d.o.b. 15-2-1988 and age per is 15-2-2000 the result is 12 (which is
correct). But when d.o.b. is 15-2-1987 and age per is 15-2-2000 the
result is
also 12 (which should be 13). How can I solve this problem?!
The code is
ActiveCell.Offset(0, 1) = Int(DateDiff("d", ActiveCell.Offset(0,
0).Value,
Range("c2").Value) / 365.25)
Regards
Basta1980
|