On 5/14/07, Andrus <kobruleht2@hot.ee> wrote:
> How to create function which returns persons age in years?
[snip]
What's wrong with age()?
# select age('1879-03-14'::date);
age
------------------
128 years 2 mons
# select extract(year from age('1879-03-14'::date));
date_part
-----------
128
You can give age() two arguments to calculate the difference between
two dates to get an interval:
# select age('1955-04-18'::date, '1879-03-14'::date);
age
-----------------------
76 years 1 mon 4 days
If you subtract two date values you will get the number of days
instead of an interval.
Documentation:
http://www.postgresql.org/docs/8.2/interactive/functions-datetime.html
Alexander.