Re: extract or date_part on an interval? How many e

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Cc: Bryce Nesbitt <bryce1(at)obviously(dot)com>
Subject: Re: extract or date_part on an interval? How many e
Date: 2008-01-28 02:56:58
Message-ID: 200801271856.58853.aklaver@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sunday 27 January 2008 6:30 pm, Bryce Nesbitt wrote:
> Hmm. Seemed so simple. But how do I get the number of years an
> interval represents? extract is clearly the wrong way:
>
> stage=# select 'now()-'1987-02-01' as interval,extract(year from
> now()-'1987-02-01') as age;
> interval | age
> --------------------------+-----
> 7665 days 18:05:51.660345 | 0
>
> select EXTRACT(year FROM INTERVAL '7665 days'); gives the same result.
>
> select EXTRACT(day FROM now()-'1987-02-01')/365 as age; seems messy.
> select (now()-'1987-02-01')/365; gives extraneous junk.
>
> Thanks!

SELECT age('1987-02-01'::timestamp);
age
--------------------------
20 years 11 mons 26 days
(1 row)

--
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2008-01-28 03:10:40 Re: extract or date_part on an interval? How many e
Previous Message Bryce Nesbitt 2008-01-28 02:30:59 extract or date_part on an interval? How many e