Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    212

    Question 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. #2
    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. #3
    Join Date
    Mar 2007
    Posts
    212
    Quote Originally Posted by pootle flump View Post
    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. #4
    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. #5
    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 % 3600, 0), 108), 6)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  6. #6
    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
  •