[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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.
0
lordGByron
Asked:
lordGByron
3 Solutions
 
Rajkumar GsSoftware 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)

Open in new window

0
 
Anthony PerkinsCommented:
Is this what you mean:
DECLARE @Seconds integer
SET @Seconds = 12345

SELECT CAST(@Seconds / 3600 AS varchar(10)) + ':' + CAST(@Seconds % 3600 AS varchar(10))

Open in new window

0
 
LowfatspreadCommented:
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now