Age function

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: Age function
Date: 2007-05-14 11:43:34
Message-ID: f29i2e$19c0$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How to create function which returns persons age in years?

Function parameters:

ldDob - Day Of birth
ldDate - Day where age is returned

I tried

CREATE OR REPLACE FUNCTION public.age(date, date, out integer) IMMUTABLE AS
$_$
SELECT floor(INT($2::text::integer-$1::text::integer)/10000);
$_$ language sql

but got

ERROR: syntax error at or near "("

In VFP I can use

RETURN floor(INT((VAL(DTOS(ldDate))-VAL(DTOS(ldDob))))/10000)

or

RETURN (year(ldDate) - year(ldDOB) - ;
iif( str(month(ldDate),2) + str(day(tdDate),2) < ;
str(month(tdDOB),2) + str(day(tdDOB),2), 1, 0) )

Andrus.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nicolas Barbier 2007-05-14 12:03:25 Re: primary key index
Previous Message Hannes Dorbath 2007-05-14 10:42:39 Re: tsearch2 problem