Converting hh:mi:ss format to seconds

Database

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!

3 REPLIES
Enthusiast

Re: Converting hh:mi:ss format to seconds

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

Re: Converting hh:mi:ss format to seconds

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.

Enthusiast

Re: Converting hh:mi:ss format to seconds

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