Re: interval question - Mailing list pgsql-general

From Eric G. Miller
Subject Re: interval question
Date
Msg-id 20010305193941.A5119@calico.local
Whole thread Raw
In response to interval question  ("Fernando P. Schapachnik" <fernando@schapachnik.com.ar>)
List pgsql-general
On Mon, Mar 05, 2001 at 09:59:40PM -0300, Fernando P. Schapachnik wrote:
> Hello:
>     Maybe somebody on the list can give me a hand with this. I
> have:
>
> id serial,
> start time,
> duration time
>
>     (That is, ids have an start time and a duration).
>
>     I want to know which ids are current, ie, which satisfy
> start<=now<=start+duration.
>
>     The problem is that start+duration is an interval, and I
> can't find the way to cast now to interval or interval to time or
> tinterval in order to make the comparison.

Maybe something like:

CREATE start_stop (
 id SERIAL,
 start DATETIME,
 stop DATETIME
);

INSERT INTO start_stop (start, stop) VALUES (now(), now() + '1:00');

SELECT id from start_stop WHERE now() BETWEEN start AND stop;

--
Eric G. Miller <egm2@jps.net>

pgsql-general by date:

Previous
From: "Ian deSouza"
Date:
Subject: Inserting values into a SERIAL field
Next
From: Louis-David Mitterrand
Date:
Subject: Re: avoiding endless loop in an UPDATE trigger