pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martín Marqués <martin@bugs.unl.edu.ar>
To: Brandon Metcalf <bmetcalf@nortel.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: query for records based on date
Date: Mon, 21 Feb 2005 17:42:54 -0300
Message-ID: <200502211742.55144.martin@bugs.unl.edu.ar> (raw)
In-Reply-To: <Pine.LNX.4.58L.0502211356580.24449@cash.rhiamet.com>
References: <Pine.LNX.4.58L.0502211356580.24449@cash.rhiamet.com>

El Lun 21 Feb 2005 17:00, Brandon Metcalf escribió:
> If I have a table with an attribute of type "timestamp without time
> zone", what is the best way to query that table for records that are
> older than, say, one week.
>
> I suppose I could get the current time in epoch seconds and the time of
> the attribute in the same, and select those records where the difference
> is greater than the number of seconds in a week.  Is there something
> easier like
>
>   SELECT * FROM table WHERE attribute IS OLDER THAN one week;

SELECT * FROM table WHERE attribute < (now()::DATE - 7)::TIMESTAMP;

-- 
 17:41:37 up 162 days,  7:36,  2 users,  load average: 0.11, 0.12, 0.08
-----------------------------------------------------------------
Martín Marqués        | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica  |  DBA, Programador, Administrador
             Universidad Nacional
                  del Litoral
-----------------------------------------------------------------



view thread (4+ messages)  latest in thread

Message-ID: <200502211742.55144.martin@bugs.unl.edu.ar>
Permalink:  ../200502211742.55144.martin@bugs.unl.edu.ar/
Also on:    postgresql.org/message-id/200502211742.55144.martin@bugs.unl.edu.ar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: martin@bugs.unl.edu.ar, bmetcalf@nortel.com
  Subject: Re: query for records based on date
  In-Reply-To: <200502211742.55144.martin@bugs.unl.edu.ar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox