471,092 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

formating interval question

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
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #1
2 1094
On Fri, 24 Sep 2004 11:58:44 +0100
mi**@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
Nov 23 '05 #2
mike <mi**@bristolreccc.co.uk> writes:
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


You could always EXTRACT(EPOCH ...) to get total seconds and then
divide. I am not sure whether EXTRACT(HOUR ...) would give the
same answer, or just the hours portion of the normal printout.
But anyway, see EXTRACT.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rob | last post: by
1 post views Thread by thechaosengine | last post: by
1 post views Thread by Ed Smith | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.