Subject Re: [firebird-support] age calculation Svein Erling Tysvaer 2006-10-21T09:45Z
To always get things correct, I normally do something like

WHEN extract(month from current_date) >
extract(month from BirthDate)
OR (extract(month from current_date) =
extract(month from BirthDate)
AND extract(day from current_date) >=
extract(day from BirthDate)) then
extract(year from current_date) -
extract(year from BirthDate)
ELSE //Birthday yet to come
extract(year from current_date) -
extract(year from BirthDate) - 1
END

Dividing by 365.25 is a very close approximation, but two persons that
are exactly the same number of days, may be a different number of years
due to one of them having lived one leap year more than the other (a
child that was born 365 days ago, is one year old unless there has been
a February 29 since he was born).

HTH,
Set

Fernando Salaices wrote:
> Hello all.
>
> I have a question about how to calculate the correct age of a person
> using the date of birth. I'm trying something like this:
>
> select
> cast('10/20/2005' as date) AS CURRENTDATE
> ,(cast((current_date - cast('10/21/1974' as date)) as float)/365) as
> YEARS_OF_LIFE_OF_PERSON
> from rdb\$database;
>
> In this query, I subtract from the current date (october 20, 2006 in
> this case) the DOB (october 21, 1974). It should give me a number just
> below 32, but I get 32.0191780821918
>
> I thought it was a rounding error, that is why I started casing to FLOAT.
>
> What am I doing wrong?