Re: how to get a number of seconds in some interval ? - Mailing list pgsql-admin

From Shane Ambler
Subject Re: how to get a number of seconds in some interval ?
Date
Msg-id 48295481.50800@Sheeky.Biz
Whole thread Raw
In response to Re: how to get a number of seconds in some interval ?  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Responses Re: how to get a number of seconds in some interval ?  ("Scott Marlowe" <scott.marlowe@gmail.com>)
List pgsql-admin
Scott Marlowe wrote:

> True.  But that's only because it doesn't have a date to work against.
>  If you run:
>
> select '2007-02-01 12:00:00'::timestamp + '1 month'::interval;
> you get: 2007-03-01 12:00:00
>
> If you run:
> select '2007-03-01 12:00:00'::timestamp + '1 month'::interval;
> you get:  2007-04-01 12:00:00
>
> Then, if we run:
>  select ('2007-03-01 12:00:00'::timestamp + '1 month'::interval) -
> '2007-03-01 12:00:00'::timestamp;
> we get: 31 days
>
> But if we run:
>  select ('2007-02-01 12:00:00'::timestamp + '1 month'::interval) -
> '2007-02-01 12:00:00'::timestamp;
> we get: 28 days
>
> So, I'm not sure how many days a month has.

Try looking at a calendar.;-)

You will find that these are the exact days between the two dates. Feb
has 28 days, so 1st of feb plus 1 month puts you at 1st of march

march has 31 days so 1st of march plus 1 month puts you at 1st of april.

Try a leap year -

select ('2008-02-01 12:00:00'::timestamp + '1 month'::interval) -
'2008-02-01 12:00:00'::timestamp;
  ?column?
----------
  29 days
(1 row)


--

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz

pgsql-admin by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: how to get a number of seconds in some interval ?
Next
From: "Scott Marlowe"
Date:
Subject: Re: how to get a number of seconds in some interval ?