Re: interval question

From: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: interval question
Date: 2001-03-06 03:39:41
Message-ID: 20010305193941.A5119@calico.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jps(dot)net>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Wood 2001-03-06 04:48:07 Re: MySQLs Describe emulator!
Previous Message Paulo Parola 2001-03-06 03:38:52 Re: Re: RPMs for PHP accessing PostgreSQL via ODBC over RedHat