Re: Date / interval question

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Date / interval question
Date: 2008-04-11 05:02:44
Message-ID: 20080411050243.GA31117@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Thu, dem 10.04.2008, um 21:26:14 -0600 mailte kevin kempter folgendes:
> I can get the number of days since the start of the fiscal year like
> this:
>
> # select date '01/01/2007' - date '09/01/2006' as interval;
> interval
> ----------
> 122
> (1 row)
>
> However I'm stumped [er how to get the number of months from
> 09/01/2007 thru 01/01/2007
>
> Thoughts ?

test=*# select age(date '01/01/2007',date '09/01/2006');
age
--------
4 mons

For a longer interval:

test=*# select age(date '01/01/2007',date '09/05/2005');
age
-----------------------
1 year 3 mons 26 days
(1 row)

test=*# select extract('month' from age(date '01/01/2007',date '09/05/2005'));
date_part
-----------
3
(1 row)

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Reece Hart 2008-04-11 05:17:25 tsearch2 and hyphenated terms
Previous Message kevin kempter 2008-04-11 03:26:14 Date / interval question