Re: Intervals

From: Andrei Gaspar <andi(at)softnrg(dot)dnttm(dot)ro>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Intervals
Date: 2005-04-26 10:22:23
Message-ID: 426E165F.9010509@softnrg.dnttm.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I had the same problem and wrote a small function

create function hours(timestamp without time zone, timestamp without
time zone) RETURNS integer as
$$select cast( (cast($2 as date) - cast($1 as date)) * 24 + extract(hour
from cast($2 as time) - cast($1 as time)) as integer)$$ language SQL
IMMUTABLE;

Andrei

Jake Stride wrote:

>Is there a way to convert in interval into hours? I have a table that
>records the amount of time worked by a person and want to sum up all the
>hours, however with the column being an interval once you reach more
>than 24 hours it turns that into a day. This is not what I want so
>instead of outputting 1day 2:00:00 I would want to output 26:00:00 is
>this possible?
>
>Thanks
>
>Jake
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>
>
>

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.3 - Release Date: 4/25/2005

In response to

  • Intervals at 2005-04-26 09:47:08 from Jake Stride

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2005-04-26 10:32:00 Re: oid wraparound
Previous Message Russell Smith 2005-04-26 10:17:30 Re: oid wraparound