# Thread: Convert seconds to hh:mm:ss

1. Registered User
Join Date
Mar 2007
Posts
212

## Unanswered: Convert seconds to hh:mm:ss

Hi

I have table which stores seconds as an integer. I use the following to convert to hh:mm:ss

Code:
`select convert(varchar(8),dateadd(ss,yoursecondsvaluefield,0),108)`
however this only works for values up to 24 hrs. Does any one know a solution so that yo can get the hh:mm:ss format for hours that are greater than 24hrs?

any help appreciated.

2. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
You need to show the result you require for an example greater than 24hrs.

3. Registered User
Join Date
Mar 2007
Posts
212
Originally Posted by pootle flump
You need to show the result you require for an example greater than 24hrs.
try converting the following into hh:mm:ss using the following and you will see what i mean:

Code:
`select convert(varchar(8),dateadd(ss,118800,0),108)`
How would you format/convert seconds where they are greater than 86400?

4. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
I know what will happen. Saying "I don't want this" doesn't help - I need to know what you want instead.

5. Resident Curmudgeon
Join Date
Feb 2004
Location
In front of the computer
Posts
15,579
Provided Answers: 54
Code:
```DECLARE @i INT
SET @i = 2000

SELECT Cast(@i / 3600 AS VARCHAR(8)) + Right(Convert(VARCHAR(8)
, DateAdd(s, @i &#37; 3600, 0), 108), 6)```
-PatP

6. Registered User
Join Date
Aug 2009
Posts
262
Pat Phelan - you got here one day ahead of me ...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•