Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

extract or date_part on an interval? How many e


  • From: Bryce Nesbitt <bryce1(at)obviously(dot)com>
  • To: pgsql-sql(at)postgresql(dot)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> <text/plain>

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/





Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group