March 31, 2014

SQL Server - Convert Seconds into Hours:Minutes:Seconds format

This query can help to change seconds into Hours:Minutes:Seconds format.

DECLARE @TimeinSecond INT
SET @TimeinSecond = 8000 -- Change the seconds
SELECT RIGHT('0' + CAST(@TimeinSecond / 3600 AS VARCHAR),2) + ':' +
RIGHT('0' + CAST((@TimeinSecond / 60) % 60 AS VARCHAR),2)  + ':' +
RIGHT('0' + CAST(@TimeinSecond % 60 AS VARCHAR),2)

Output:
02:13:20

No comments: