Re: subtract a day from the NOW function

From: "Campbell, Lance" <lance(at)uiuc(dot)edu>
To: "Osvaldo Kussama" <osvaldo_kussama(at)yahoo(dot)com(dot)br>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: subtract a day from the NOW function
Date: 2007-06-08 14:15:14
Message-ID: A3AC4FA47DC0B1458C3E5396E685E63302395E2C@SAB-DC1.sab.uiuc.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Osvaldo,
Thanks! This is a great solution. It definitely is very easy to read. I like to have my SQL as clean as my java code. I ended up using the following:

SELECT some_timestamp FROM some_table WHERE some_timestamp::date > 'yesterday'::date;

Thanks,

Lance Campbell
Project Manager/Software Architect
Web Services at Public Affairs
University of Illinois
217.333.0382
http://webservices.uiuc.edu

-----Original Message-----
From: Osvaldo Kussama [mailto:osvaldo_kussama(at)yahoo(dot)com(dot)br]
Sent: Thursday, June 07, 2007 4:41 PM
To: Campbell, Lance
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] subtract a day from the NOW function

--- "Campbell, Lance" <lance(at)uiuc(dot)edu> escreveu:

> Table
>
> Field "some_timestamp" is a timestamp.
>
>
>
> In a "WHERE" statement I need to compare a timestamp
> field in a table
> "some_timestamp" to now() - one day.
>
>
>
> Example:
>
>
>
> SELECT some_timestamp WHERE to_char(some_timestamp,
> 'YYYYMMDD') >
> (to_char(now(), 'YYYYMMDD') - 1 day);
>
>
>
> The statement "to_char(now(), 'YYYYMMDD') - 1 day)"
> is obviously
> incorrect. I just need to know how to form this in
> a way that will
> work.
>
>
>
> If there is an entirely different solution I am all
> for it. Do note
> that I started down this path because I want to
> exclude the hour,
> minutes and seconds found in the field
> "some_timestamp" and in the
> function now().
>

Try:
SELECT some_timestamp
WHERE some_timestamp > 'yesterday'::timestamp;

Look 8.5.1.5. Special Values at:
http://www.postgresql.org/docs/8.2/interactive/datatype-datetime.html

[]s
Osvaldo


____________________________________________________________________________________
Novo Yahoo! Cadê? - Experimente uma nova busca.
http://yahoo.com.br/oqueeuganhocomisso

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas 'ads' Scherbaum 2007-06-08 14:25:48 Re: Live CD status
Previous Message Tom Lane 2007-06-08 14:11:05 Re: Record Types Structure in PL/pgSQL

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2007-06-08 14:20:30 Re: the right time to vacuum database?
Previous Message Charles.Hou 2007-06-08 13:29:55 Re: the right time to vacuum database?