pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shane Ambler <pgsql@Sheeky.Biz>
To: Scott Marlowe <scott.marlowe@gmail.com>
Cc: Achilleas Mantzios <achill@matrix.gatewaynet.com>
Cc: pgsql-admin@postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Julius Tuskenis <julius@nsoft.lt>
Subject: Re: how to get a number of seconds in some interval ?
Date: Tue, 13 May 2008 18:12:41 +0930
Message-ID: <48295481.50800@Sheeky.Biz> (raw)
In-Reply-To: <dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com>
References: <482849B0.6050103@nsoft.lt>
	<200805121801.35101.achill@matrix.gatewaynet.com>
	<20080.1210604951@sss.pgh.pa.us>
	<200805130956.51872.achill@matrix.gatewaynet.com>
	<dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com>

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



view thread (11+ messages)  latest in thread

Message-ID: <48295481.50800@Sheeky.Biz>
Permalink:  ../48295481.50800@Sheeky.Biz/
Also on:    postgresql.org/message-id/48295481.50800@Sheeky.Biz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: pgsql@Sheeky.Biz, scott.marlowe@gmail.com, achill@matrix.gatewaynet.com, tgl@sss.pgh.pa.us, julius@nsoft.lt
  Subject: Re: how to get a number of seconds in some interval ?
  In-Reply-To: <48295481.50800@Sheeky.Biz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox