Friday, August 19, 2011

Convert an 8 digit integer into hhmmss format

Declare @intSeconds int
Set @intSeconds = 99999999

SELECT
Total_Duration = CONVERT( VARCHAR, RIGHT('00000' + RTRIM(@intSeconds/3600), 5)
+ 'hrs ' + RIGHT('00' + RTRIM((@intSeconds % 3600) / 60), 2)
+ 'mins ' + RIGHT('00' + RTRIM((@intSeconds % 3600) % 60), 2)
+ 'secs ')

No comments: