## Re: how to get a number of seconds in some interval ?

From: Shane Ambler Scott Marlowe Achilleas Mantzios , pgsql-admin(at)postgresql(dot)org, Tom Lane , Julius Tuskenis Re: how to get a number of seconds in some interval ? 2008-05-13 08:42:41 48295481.50800@Sheeky.Biz (view raw, whole thread or download thread mbox) 2008-05-12 13:44:16 from Julius Tuskenis  2008-05-12 14:24:38 from Achilleas Mantzios   2008-05-12 15:01:34 from Achilleas Mantzios    2008-05-12 15:09:11 from Tom Lane     2008-05-13 06:20:09 from Julius Tuskenis     2008-05-13 06:56:50 from Achilleas Mantzios      2008-05-13 08:22:28 from "Scott Marlowe"       2008-05-13 08:41:00 from Achilleas Mantzios       2008-05-13 08:42:41 from Shane Ambler        2008-05-13 08:48:32 from "Scott Marlowe"      2008-05-13 14:15:27 from Tom Lane 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

```