Unix Technical Forum

Date / interval question

This is a discussion on Date / interval question within the Pgsql General forums, part of the PostgreSQL category; --> Hi List; I'm populating a time dimension. I need to get the number of days since the start of ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 02:05 AM
kevin kempter
 
Posts: n/a
Default Date / interval question

Hi List;

I'm populating a time dimension. I need to get the number of days
since the start of the fiscal year and also the number of months since
the start of the fiscal year based on the current 'date' being
processed.

Example:

my current process date is 01/01/2007
start date of fiscal year is 09/01/2006

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 ?

Thanks in advance...


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 02:05 AM
=?UTF-8?Q?Rodrigo_E._De_Le=C3=B3n_Plicet?=
 
Posts: n/a
Default Re: Date / interval question

On Thu, Apr 10, 2008 at 10:26 PM, kevin kempter
<kevin@kevinkempterllc.com> wrote:
> However I'm stumped [er how to get the number of months from 09/01/2007
> thru 01/01/2007


select extract(month from (age(date '2007-1-1', date '2006-9-1')));

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 02:05 AM
A. Kretschmer
 
Posts: n/a
Default Re: Date / interval question

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com