pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryce Nesbitt <bryce1@obviously.com>
To: pgsql-sql@postgresql.org
Subject: extract or date_part on an interval?  How many e
Date: Sun, 27 Jan 2008 18:30:59 -0800
Message-ID: <479D3E63.2080601@obviously.com> (raw)

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!

-- 
----
Visit http://www.obviously.com/





view thread (5+ messages)  latest in thread

Message-ID: <479D3E63.2080601@obviously.com>
Permalink:  ../479D3E63.2080601@obviously.com/
Also on:    postgresql.org/message-id/479D3E63.2080601@obviously.com

 · 

reply

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: bryce1@obviously.com
  Subject: Re: extract or date_part on an interval?  How many e
  In-Reply-To: <479D3E63.2080601@obviously.com>

* 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