From: Adrian Klaver <aklaver@comcast.net>
To: pgsql-sql@postgresql.org
Cc: Bryce Nesbitt <bryce1@obviously.com>
Subject: Re: extract or date_part on an interval? How many e
Date: Sun, 27 Jan 2008 18:56:58 -0800
Message-ID: <200801271856.58853.aklaver@comcast.net> (raw)
In-Reply-To: <479D3E63.2080601@obviously.com>
References: <479D3E63.2080601@obviously.com>
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@comcast.net
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: aklaver@comcast.net, bryce1@obviously.com
Subject: Re: extract or date_part on an interval? How many e
In-Reply-To: <200801271856.58853.aklaver@comcast.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox