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

Re: Date Foo.

From: Brian Knox <laotse(at)aol(dot)net>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Date Foo.
Date: 2004-02-20 20:25:36
Message-ID: 40366D40.4030405@aol.net (view raw or flat)
Thread:
Lists: pgsql-sql
Sorry, Not looking for a way to extract a month from a timestamp. I'm 
looking for a way to convert an interval from days to months. I'm not 
sure after digging into it that there is a way to handle it in SQL, as 
the interval that results from subtracting one timestamp from another is 
not away of what months the interval spans, so there'd be no proper way 
to take month lengths into account.

I gave up on the sql and used Date::Calc from Perl. Thanks for your 
answer anyway.

scott.marlowe wrote:
> On Thu, 19 Feb 2004, Brian Knox wrote:
> 
> 
>>( sorry if this is a repeat, my mail server is being wonky today )
>>
>>I'm looking for a way, within SQL, given a starting date and an ending 
>>date, to get back the number of months between the start and end date. 
>>If I "SELECT end_date - start_date", I get back an interval in days; I 
>>need months.
> 
> 
> Maybe date_part?
> 
> select date_part('month','2004-08-02 12:00:00'::timestamp) - 
> date_part('month','2004-05-01 12:00:00'::timestamp);
> 

In response to

Responses

pgsql-sql by date

Next:From: scott.marloweDate: 2004-02-20 21:18:03
Subject: Re: Date Foo.
Previous:From: Josh BerkusDate: 2004-02-20 18:53:36
Subject: Re: Row counts/data changes. Any catalog table that has this info?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group