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
 Seconds to HH:MM:SS

Author  Topic 

amodi
Yak Posting Veteran

83 Posts

Posted - 2009-08-29 : 16:11:38
Hello Friends,

I have a column that contains seconds, I want to display that seconds in the following format : HH:MM:SS

For example:

if i have 9906 seconds then i want it as
02:45:06

Thanks.

amodi
Yak Posting Veteran

83 Posts

Posted - 2009-08-29 : 16:25:26
Hello Friends,

I tried the following:

seconds = 9906

convert(varchar,9906/(3600)) + ':'+convert(varchar,9906%(3600)/60)+':'+convert(varchar,9906%60)

output: 2:45:6

Is it possible to the output as 02:45:06 ???

Thanks


Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-29 : 16:41:37
[code]right(('00' + convert(varchar,9906/(3600))),2) + ':'+right(('00'+ convert(varchar,9906%(3600)/60)),2)+':'+ right(('00'+convert(varchar,9906%60)),2)[/code]
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2009-08-29 : 17:05:04
Thanks vijay. It works!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-29 : 17:09:06
welcome
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-30 : 00:32:08
Hi, See this below link

http://www.sql-server-helper.com/tips/date-formats.aspx

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-31 : 02:35:50
declare @time int
set @time=9906
select convert(varchar(10),dateadd(second,@time,0),108)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -