Re: How to get the previous date?

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to get the previous date?
Date: 2009-10-17 11:41:47
Message-ID: hbcahr$k31$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 2009-10-14, Shruthi A <shruthi(dot)iisc(at)gmail(dot)com> wrote:
> --0016e64698e4af821f0475e1f43d
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> I'm using Enterprise DB PostgresPlus version 8.3.
> Is there is a simple function or command like previous_date(mydate) which
> when passed a particular date, simply returns the previous date? I tried
>
> mydate - 1
>
> but this doesnt work.

it should, if mydate is a date variable.

if it's some sort of timestamp more care is needed

mytimestamp - interval'1 day'

also don't use interval'24h' unless you want 24h, because not all days are 24h

select timestamptz'2009-09-28 00:30' - interval'24 h' ;
?column?
------------------------
2009-09-26 23:30:00+12

(the interval crosses the local start of DST)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rob Sargent 2009-10-18 05:26:56 Re: Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function
Previous Message matthias schoeneich 2009-10-17 11:29:32 Re: Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function