Subject | Re: age calculation |
---|---|
Author | Adam |
Post date | 2006-10-21T06:17:20Z |
--- In firebird-support@yahoogroups.com, Daniel Rail <daniel@...>
wrote:
is not a leap year unless the year is divisible by 400 (eg 1600,
2000) when it is still a leap year.
Depending on the dates you are talking about you may need to take
this into account.
Adam
wrote:
>person
> Hi,
>
> At October 20, 2006, 10:47 PM, Fernando Salaices wrote:
>
> > I have a question about how to calculate the correct age of a
> > using the date of birth. I'm trying something like this:as
>
> > select
> > cast('10/20/2005' as date) AS CURRENTDATE
> > ,(cast((current_date - cast('10/21/1974' as date)) as float)/365)
> > YEARS_OF_LIFE_OF_PERSONin
> > from rdb$database;
>
> > In this query, I subtract from the current date (october 20, 2006
> > this case) the DOB (october 21, 1974). It should give me a numberjust
> > below 32, but I get 32.0191780821918to FLOAT.
>
> > I thought it was a rounding error, that is why I started casing
>And don't forget if the year is divisible by 100 (eg 1800, 1900) it
> > What am I doing wrong?
>
> Try dividing by 365.25. And, you should see the result that you are
> expecting. Don't forget that there's a leap year every 4 years that
> has 366 days.
is not a leap year unless the year is divisible by 400 (eg 1600,
2000) when it is still a leap year.
Depending on the dates you are talking about you may need to take
this into account.
Adam