All Forums Database
vikram1229 3 posts Joined 08/13
26 Jun 2014
Converting hh:mi:ss format to seconds

Hi,,
 
 
I need to convert time column into seconds.
 
for example:01:55:30 to 6930
 
Is there any function to convert this?
Your help is appreciated.
thanks!
 
 
 

Raja_KT 1246 posts Joined 07/09
26 Jun 2014

Try this:
select cast(interval '01:55:30' hour to second) as interval second(4) )

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
Street Children suffer not by their fault. We can help them if we want.

dnoeth 4628 posts Joined 11/04
27 Jun 2014

Hi Raja,
this will fail after 02:46:39 = 9999 seconds.
Better use

   EXTRACT(HOUR   FROM t) * 3600
 + EXTRACT(MINUTE FROM t) * 60
 + EXTRACT(SECOND FROM t)

It's easy to put this calculation in a SQL UDF.

Dieter

Raja_KT 1246 posts Joined 07/09
27 Jun 2014

Oops!!!! yes. I did not test beyond that  :). Thanks. Appreciate a lot.

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
Street Children suffer not by their fault. We can help them if we want.

You must sign in to leave a comment.