Subject | Re: [firebird-support] age calculation |
---|---|
Author | Fernando Salaices |
Post date | 2006-10-24T02:13:37Z |
ok! thanks for all you answers.
On 10/21/06, Svein Erling Tysvaer <svein.erling.tysvaer@...>
wrote:
Saludos,
Fernando Salaices.
[Non-text portions of this message have been removed]
On 10/21/06, Svein Erling Tysvaer <svein.erling.tysvaer@...>
wrote:
>--
> To always get things correct, I normally do something like
>
> SELECT CASE //Birthday already been
> 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?
>
>
>
Saludos,
Fernando Salaices.
[Non-text portions of this message have been removed]