Re: Calculating the age of a person

From: Cedar Cox <cedarc(at)visionforisrael(dot)com>
To: Hans-Jürgen Schönig <hs(at)cybertec(dot)at>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Calculating the age of a person
Date: 2001-05-20 10:07:25
Message-ID: Pine.LNX.4.21.0105201306180.17381-100000@nanu.visionforisrael.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Or you could use date_trunc() in the same way as date_part() if you want
an interval instead..

SELECT date_trunc('year',age(birth)),* FROM persons LIMIT 1;

On Fri, 18 May 2001, tjk(at)tksoft(dot)com wrote:

> You are probably looking for date_part().
>
> E.g.
>
> SELECT date_part('year',age(birth)),* FROM persons LIMIT 1;
>
>
> Troy
>
>
>
> >
> > I have a table containing the birthdays of various persons. The target
> > is to compute the age of a persons.
> >
> > persons=# SELECT age(birth), * FROM persons LIMIT 1;
> > age | id | name | birth | gender |
> > income
> > -------------------------------+----+--------+------------+--------+--------
> >
> > 31 years 4 mons 16 days 23:00 | 1 | Albert | 1970-01-01 | m |
> > 35000
> > (1 row)
> >
> > When I use age() I don't get full years. Is there an easy way to round
> > ::reltime off or up without writing a function. Is there any possibility
> > to use plain SQL only?
> >
> > Hans
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2001-05-20 12:29:54 Re: timestamp bug
Previous Message Cedar Cox 2001-05-20 09:49:00 timestamp bug