The situation is you have a value in Seconds (XXX.XX), and you want to convert to HH:MM:SS using T-SQL.
Example:
- 121.25 s becomes 00:02:01.25
The situation is you have a value in Seconds (XXX.XX), and you want to convert to HH:MM:SS using T-SQL.
Example:
Using SQL Server 05 I can get this to work by using:
Convert seconds to hours in select query:
SELECT field_in_seconds,round((field_in_seconds / 3600),2) FROM a_table;
This will give you the result in decimal format. Not sure how to convert 1.50 to 1:30. Please feel free to edit my code!
For those having issues with using DATEADD and CONVERT for seconds exceeding 24 hours, we can use modulus to get around that:
If your time amount exceeds 24 hours it won't be handled correctly with the DATEADD and CONVERT methods.
The following function will handle times exceeding 24 hours (~max 35,791,394 hours).
Usage:
10000 is your value in sec