Re: Calculating the age of a person

From: "tjk(at)tksoft(dot)com" <tjk(at)tksoft(dot)com>
To: hs(at)cybertec(dot)at (=?iso-8859-1?Q?Hans=2DJ=FCrgen=20Sch=F6nig?=)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Calculating the age of a person
Date: 2001-05-18 15:53:29
Message-ID: 200105181553.IAA13471@smtp3.tksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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
>

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2001-05-18 16:00:50 Re: has anyone tried running in MAC OS X
Previous Message george young 2001-05-18 15:35:49 Re: search for groups with a user