Re: interval question

From: dev(at)archonet(dot)com
To: Fernando "P(dot) Schapachnik" <fernando(at)schapachnik(dot)com(dot)ar>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: interval question
Date: 2001-03-06 12:07:12
Message-ID: 20010306.12071200@client.archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/6/01, 12:59:40 AM, Fernando "P." Schapachnik
<fernando(at)schapachnik(dot)com(dot)ar> wrote regarding [GENERAL] interval question:

> Hello:
> Maybe somebody on the list can give me a hand with this. I
> have:
> id serial,
> start time,
> duration time

Surely "duration" should be of type interval.
Also - are you sure "start" should be time and not timestamp - depends if
you don't care about dates.

> (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.

SELECT id FROM foo WHERE start<=now() AND 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.

The cast should happen automatically. If not, you can do things like:

select now() + '10:00'::interval;
select '2001-03-13'::timestamp;

to convert into interval or a timestamp.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando P. Schapachnik 2001-03-06 12:28:00 Re: Re: interval question
Previous Message dev 2001-03-06 11:58:00 Re: List of all system tables.