Home >Database >Mysql Tutorial >How to Convert an Integer Representing Time to HH:MM:SS:00 Format in SQL Server 2008?
Convert Integer Time to HH:MM:SS:00 in SQL Server 2008
Question:
In SQL Server 2008, it is necessary to transform an integer time value into the time format HH:MM:SS:00. Additionally, it is essential to understand whether the '00' in this format represents milliseconds.
Answer:
To convert an integer time to HH:MM:SS:00, utilize the following steps:
The '00' in the time format HH:MM:SS:00 represents milliseconds.
Example:
Consider the integer time 10455836.
SELECT (@T / 1000000) % 100 AS hour, (@T / 10000) % 100 AS minute, (@T / 100) % 100 AS second, (@T % 100) * 10 AS millisecond
Result:
hour minute second millisecond 10 45 58 360
Alternatively, you can use the following query for a more comprehensive result:
SELECT DATENAME(HOUR, DATETIMEFROMPARTS(@T / 1000000 % 100, @T / 10000 % 100, @T / 100 % 100, @T % 100 * 10)) AS hour, DATENAME(MINUTE, DATETIMEFROMPARTS(@T / 1000000 % 100, @T / 10000 % 100, @T / 100 % 100, @T % 100 * 10)) AS minute, DATENAME(SECOND, DATETIMEFROMPARTS(@T / 1000000 % 100, @T / 10000 % 100, @T / 100 % 100, @T % 100 * 10)) AS second, DATENAME(MILLISECOND, DATETIMEFROMPARTS(@T / 1000000 % 100, @T / 10000 % 100, @T / 100 % 100, @T % 100 * 10)) AS millisecond
Output:
hour minute second millisecond 10 45 58 360
This method also clearly identifies the time components as hour, minute, second, and millisecond.
The above is the detailed content of How to Convert an Integer Representing Time to HH:MM:SS:00 Format in SQL Server 2008?. For more information, please follow other related articles on the PHP Chinese website!