Sunday, February 19, 2012

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

You can do:

declare @.seconds int
set @.seconds = 241
select convert(char(8), dateadd(second, @.seconds, ''), 114)

|||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

No comments:

Post a Comment