Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I have a timestamp of 00:48:38 and I need to convert it to seconds. In seconds format it should calculate to 2918 seconds.Anyone have any idea how to do this in tsql?Thanks,Ninel
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2009-03-23 : 11:21:05
In what datatype is your "timestamp" stored? If some flavor of varchar are there leading zeros for values < 10? (ie: '04:01:08')EDIT:assuming varchar with leading zeros
select ts ,convert(int, substring(ts, 1,2)) * 60 * 60 + convert(int, substring(ts, 4,2)) * 60 + convert(int, substring(ts, 7,2)) as [seconds]from ( select '00:48:38' ts union all select '04:01:08' ) d
Be One with the OptimizerTG
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts
Posted - 2009-03-23 : 12:11:43
[code]select *, DiffSeconds = datediff(ss,0,ts)from ( -- Test data select '00:48:38' ts union all select '04:01:08' ) aResults:ts DiffSeconds -------- ----------- 00:48:38 291804:01:08 14468(2 row(s) affected)[/code]CODO ERGO SUM