Re: formating interval question - Mailing list pgsql-general

From Jesper K. Pedersen
Subject Re: formating interval question
Date
Msg-id 20040924142009.30044256.jkp@solnet.homeip.net
Whole thread Raw
In response to formating interval question  (mike <mike@bristolreccc.co.uk>)
List pgsql-general
On Fri, 24 Sep 2004 11:58:44 +0100
mike@bristolreccc.co.uk (mike) wrote:

> I have an interval field which is used to calculate total hours.
> At present it outputs as days hours minutes
> Is there any way to output as total hours
> I have tried to_char(field,'HH:MM')
> but I get wierd results like -51 or -5
>

From the top of my head i think could probably to do something like
this:

    extract(epoch from your_time_interval)/3600


It basically finds the "age" of your interval in seconds. The /3600 is
to find the result in hours.

If you for instance want the result with just one decimal like xxxx.y
then you can do it like this:

    round(extract(epoch from your_time_interval)/360)/10

I hope this helps.


Best regards
Jesper K. Pedersen

pgsql-general by date:

Previous
From: "John Liu"
Date:
Subject: core dump on select
Next
From: pwbyrne@hotmail.com
Date:
Subject: porting a full Ms Sql Server to postgres