Re: incrementing and decrementing dates by day increments - Mailing list pgsql-general

From Tom Lane
Subject Re: incrementing and decrementing dates by day increments
Date
Msg-id 22977.1067237231@sss.pgh.pa.us
Whole thread Raw
In response to Re: incrementing and decrementing dates by day increments  (BlakJak <blakjak@blakjak.sytes.net>)
List pgsql-general
BlakJak <blakjak@blakjak.sytes.net> writes:
> So to get "five days ago", you would use
> now() - interval '5 days'

Actually, given that the OP seems to only want a date result and not a
time-of-day, I'd suggest something like

    current_date - 5

The date-plus-integer and date-minus-integer operators do exactly what
I think is being asked for.  timestamp-minus-interval does computations
including fractional days, which will just confuse matters
... especially near DST transition days.  For instance, right now I get

regression=# select now();
              now
-------------------------------
 2003-10-27 01:45:14.458268-05
(1 row)

regression=# select now() - interval '5 days';
           ?column?
------------------------------
 2003-10-22 02:45:20.22788-04
(1 row)

which is correct in one sense but is surely going to confuse some
people.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: foxpro to postgresql7.1
Next
From: Yonatan Goraly
Date:
Subject: Slow query