Convert Integer To Time Only In SELECT

I have stored, as seconds, a duration in a table. I would like to use a SELECT statement to retrieve the contents of the column but display them as a time. For example:

45 = 0:00:45
241 = 0:04:01
575 = 0:09:35

and so on...

I have tried using the built-in CONVERT() function but always end up with StartDate + Integer and a time of 0:00:00.

Can anyone help please

Cheers,

Roy


Answer this question

Convert Integer To Time Only In SELECT

  • DarrenK

    Thanks for this.

    I took your example and turned it in to this which works:

    SELECT CONVERT(char(8), DATEADD(second, Duration, ''), 114) AS Duration ...

    Cheers,

    Roy

  • Tom De Cort

    You can do:
     
    declare @seconds int
    set @seconds = 241
    select convert(char(8), dateadd(second, @seconds, ''), 114)


  • Convert Integer To Time Only In SELECT