Re: Intervals

From: Jake Stride <jake(dot)stride(at)senokian(dot)com>
To: Andrei Gaspar <andi(at)softnrg(dot)dnttm(dot)ro>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Intervals
Date: 2005-04-26 12:23:31
Message-ID: 426E32C3.80205@senokian.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

That is helpful, I have created a slightly different function that
returns an interval in the format HH:MM not sure if it will help anyone
or anyone has any suggestions to improve it:

create function hours(interval) returns varchar as 'SELECT
floor(extract(epoch from $1)/3600) || \':\' || (cast(extract(epoch FROM
$1) AS integer)%3600)/60;' language SQL IMMUTABLE;

Thanks

Jake

Andrei Gaspar wrote:

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

--
Jake Stride

Senokian Solutions Ltd
The TechnoCentre
Coventry University Technology Park
Puma Way
Coventry
CV1 2TT

T: 0870 744 2030
F: 0870 460 2623
M: 07713 627 304
E: jake(dot)stride(at)senokian(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2005-04-26 13:10:17 Re: savepoints
Previous Message Sean Davis 2005-04-26 11:06:37 Re: pgadminIII - creating servers