# Converting Seconds to Hours and Minutes

I have the number of seconds but I want to convert them to hh:ss.  What is the syntax for converting to the number of hours with the left over Mod going the number of seconds.

Thanks.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Software EngineerCommented:
You may try this script

Courtesy:- http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_22893480.html

Raj
``````declare @sec int
set @sec=7612
select convert(varchar(10), dateadd(second, @sec, 0) , 8)
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Is this what you mean:
``````DECLARE @Seconds integer
SET @Seconds = 12345

SELECT CAST(@Seconds / 3600 AS varchar(10)) + ':' + CAST(@Seconds % 3600 AS varchar(10))
``````
0
Commented:
assuming the number is less than 100 hours worth....
this is the general formula

select right('0'+convert(varchar(2),hrs,2)
+':'+right(+'0'+convert(varchar(2),mins),2)
+':'+right(+'0'+convert(varchar(2),secs),2)
from
(select hrs,rem/60 as mins, rem % 60 as secs from
(Select @seconds/3600 as Hrs, @seconds % 3600 as rem) as x
) as y
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.