Here I have a table with a time
column (datatype is integer
), now I need to convert the integer value to time format HH:MM:SS:00
in SQL Server 2008.
Also need clarification in the above time
format, whether 00 represents milliseconds?
Please help on this.
example: 23421155 represents 23:42:11:55; 421151 represents 00:42:11:51
Hope that it is clear now.
Convert the integer into a string and then you can use the STUFF function to insert in your colons into time string. Once you've done that you can convert the string into a time datatype.
That should be the simplest way to convert it to a time without doing anything to crazy.
In your example you also had an int where the leading zeros are not there. In that case you can simple do something like this:
You can use the following time conversion within SQL like this:
Result: 887 <- Time in minutes and 1900-01-01 14:47:00.000 <-- Minutes to time
Use the built-in MSDB.DBO.AGENT_DATETIME(20150119,0)
https://blog.sqlauthority.com/2015/03/13/sql-server-interesting-function-agent_datetime/
Result: