Age function - Mailing list pgsql-general

From Andrus
Subject Age function
Date
Msg-id f29i2e$19c0$1@news.hub.org
Whole thread Raw
Responses Re: Age function
Re: Age function
Re: Age function
List 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.

pgsql-general by date:

Previous
From: Lew
Date:
Subject: Re: are foreign keys realized as indexes?
Next
From: "Andrus"
Date:
Subject: How to implement GOMONTH function