Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 7FB4D9FBE95 for ; Thu, 7 Jun 2007 14:27:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 43987-09 for ; Thu, 7 Jun 2007 14:27:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtao05.charter.net (mtao05.charter.net [209.225.8.179]) by postgresql.org (Postfix) with ESMTP id D68859FB629 for ; Thu, 7 Jun 2007 14:27:14 -0300 (ADT) Received: from aa05.charter.net ([10.20.200.157]) by mtao05.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070607172709.MUTY1417.mtao05.charter.net@aa05.charter.net>; Thu, 7 Jun 2007 13:27:09 -0400 Received: from [10.0.1.3] (really [66.188.164.45]) by aa05.charter.net with ESMTP id <20070607172709.EGIV11983.aa05.charter.net@[10.0.1.3]>; Thu, 7 Jun 2007 13:27:09 -0400 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed Message-Id: <9938A77A-6E63-413D-8AC9-7CB741D075E6@seespotcode.net> Cc: Content-Transfer-Encoding: quoted-printable From: Michael Glaesemann Subject: Re: subtract a day from the NOW function Date: Thu, 7 Jun 2007 12:27:03 -0500 To: "Campbell, Lance" X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/61 X-Sequence-Number: 28551 > From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-=20 > owner@postgresql.org] On Behalf Of Campbell, Lance > Sent: Thursday, June 07, 2007 11:09 AM > To: pgsql-sql@postgresql.org > Subject: [SQL] subtract a day from the NOW function > SELECT some_timestamp WHERE to_char(some_timestamp, =91YYYYMMDD=92) > = =20 > (to_char(now(), =91YYYYMMDD=92) =96 1 day); On Jun 7, 2007, at 11:36 , Campbell, Lance wrote: > select to_char((now() - interval '1 day'), 'YYYYMMDD'); Why are you using to_char? Timestamps and dates support comparisons =20 just fine. SELECT CURRENT_TIMESTAMP > (CURRENT_TIMESTAMP - INTERVAL '1 day'); ?column? ---------- t (1 row) CURRENT_TIMESTAMP is SQL-spec for now(). If you're specifically looking to compare dates rather than =20 timestamps, you can cast timestamp to date: SELECT CURRENT_DATE > (CURRENT_DATE - INTERVAL '1 day')::date; ?column? ---------- t (1 row) You could also use the age function: SELECT age(CURRENT_TIMESTAMP) < INTERVAL '1 day'; SELECT age(CURRENT_TIMESTAMP) < INTERVAL '1 day'; ?column? ---------- t (1 row) Hope that helps. Michael Glaesemann grzm seespotcode net