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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert seconds to hh:mm:ss

Author  Topic 

krabople
Starting Member

17 Posts

Posted - 2008-06-19 : 10:05:32
Hi, I have a field with seconds in it, and I need to convert this so that it shows in the format hh:mm:ss. Is there an easy way to do this?

Thanks in advance,

Ben

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 10:11:45
SELECT CAST(SecondsField/3600 AS varchar(10)) + ':' + CAST((SecondsField%3600)/60 AS varchar(10)) + ':' + CAST((SecondsField%3600)%60 AS varchar(10)) FROm table


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-19 : 10:13:13
[code]SELECT CONVERT(CHAR(8), DATEADD(SECOND, @Seconds, '00:00:00'), 108)[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

krabople
Starting Member

17 Posts

Posted - 2008-06-19 : 10:21:19
Perfect, thanks very much! Glad I posted on here before I wasted anymore time writing out stupidly long workarounds!
Go to Top of Page
   

- Advertisement -