Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert HH:MM:SS to seconds?

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-09-24 : 17:26:07
Hello,

How would one convert HH:MM:SS to Seconds?

Thanks in advance!

--Phb

--PhB

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-09-24 : 17:43:57
This works if hours is between 0 and 23:
select Seconds = datediff(ss,0,'23:55:59')

Results:

Seconds
-----------
86159

(1 row(s) affected)

This works if hours can be greater than 23:
select
Seconds =
3600*substring(TM,1,charindex(':',TM)-1) +
datediff(ss,0,'00'+substring(TM,charindex(':',TM),10))

from
( Select TM = '55:55:59' ) a

Results:
Seconds
-----------
201359

(1 row(s) affected)





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -