Re: Adding seconds to a time

From: Lew <noone(at)lewscanon(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Adding seconds to a time
Date: 2010-09-17 00:22:21
Message-ID: i6ucb0$nha$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

(Top-posting corrected.)

Rob Richardson wrote:
>> And, of course, as soon as I post the question I find the answer,
>> through a more intelligent search:
>>
>> Multiply the number by a standard interval:
>> select N * '1 second'::interval

Jean-Yves F. Barbier wrote:
> Be careful though, there might be a '+1x' shift:
> SELECT now(); => 2010-09-15 15:39:02.838245+02
> see:
> SELECT now() + '1 month'::interval; => 2010-10-15 15:39:27.518034+02
>
> I guess that is an SQL rule, but it is not "legally" correct, when you
> calculate a contract termination date for example (which should be
> 2010-10-14.)

Of course it's legally correct. One month after September 15 is October 15 by
anyone's definition.

The contract termination issue is not due to miscalculation of "plus one
month" but to mistaken inclusion of the +1 month date within the contract
period. The contract needs to be understood as "from date X through but not
including X + '1 month'::interval'". The date X + '1 month'::interval still
is what it is, e.g., October 15 in your example.

--
Lew

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Mladen Gogala 2010-09-17 02:00:32 Re: Unable to use VIEWS (Ok button remains shaded)
Previous Message Richard Broersma 2010-09-16 16:24:49 Re: Unable to use VIEWS (Ok button remains shaded)