Re: Age function - Mailing list pgsql-general

From Alexander Staubo
Subject Re: Age function
Date
Msg-id 88daf38c0705141304t7c37e8f0xdfce3ec5280cb2f1@mail.gmail.com
Whole thread Raw
In response to Age function  ("Andrus" <kobruleht2@hot.ee>)
List pgsql-general
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.

pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: How to implement GOMONTH function
Next
From: Jon Sime
Date:
Subject: Re: Age function