Subject | Re: Age Calculation |
---|---|
Author | gorepj |
Post date | 2008-11-29T05:45:26Z |
--- In firebird-support@yahoogroups.com, "Valeri Mytinski"
Almost ;)
EXTRACT(YEAR FROM "date_1") - EXTRACT(YEAR FROM "date_2") - 1
+ (
CASE
WHEN EXTRACT(MONTH FROM "date_1") > EXTRACT(MONTH FROM "date_2")
THEN 1
ELSE (
CASE
WHEN ((EXTRACT(MONTH FROM "date_1") = EXTRACT(MONTH FROM "date_2"))
AND (EXTRACT(DAY FROM "date_1") >= EXTRACT(DAY FROM "date_2")))
THEN 1
ELSE 0
END)
END)
this does it - thanks for your help
<valeri.mytinski@...> wrote:
Almost ;)
EXTRACT(YEAR FROM "date_1") - EXTRACT(YEAR FROM "date_2") - 1
+ (
CASE
WHEN EXTRACT(MONTH FROM "date_1") > EXTRACT(MONTH FROM "date_2")
THEN 1
ELSE (
CASE
WHEN ((EXTRACT(MONTH FROM "date_1") = EXTRACT(MONTH FROM "date_2"))
AND (EXTRACT(DAY FROM "date_1") >= EXTRACT(DAY FROM "date_2")))
THEN 1
ELSE 0
END)
END)
this does it - thanks for your help
<valeri.mytinski@...> wrote:
>"date_2")
> The exact expression is:
>
> EXTRACT(YEAR FROM "date_1") - EXTRACT(YEAR FROM "date_2") - 1
> + (
> CASE
> WHEN EXTRACT(MONTH FROM "date_1") > EXTRACT(MONTH FROM
> THEN 1FROM "date_2"))
> ELSE (
> CASE
> WHEN ((EXTRACT(MONTH FROM "date_1") = EXTRACT(MONTH
> AND (EXTRACT(DAY FROM "date_1") > EXTRACT(DAYFROM "date_2")))
> THEN 1age.
> ELSE 0
> END)
> END)
>
> 2008/11/28, Helen Borrie <helebor@...>:
> > At 11:35 PM 28/11/2008, you wrote:
> >>I need to add a computed column to a table to evaluate a person's
> >>What is the best way to calculate age? DateDiff(Year, BirthDate,the
> >>CURRENT_DATE) seems only to take account of the year portion of
> >>dates and not the month and day parts.
> >>Regards
> >>Peter Gore
> >>Using FB2.1
> >
> > (DateDiff(Month, BirthDate, CURRENT_DATE)) /12.00
> >
> > ./heLen
> >
> >
>