Convert Military time to string representation
- by RRUZ
I have an column declarated as int (called HourMil) wich store the time in military format. i need convert this values to an formated string (HH:MM)
example
HourMil = 710 -> must be 07:10
HourMil = 1305 -> must be 13:05
Actually i am using this code (and works ok) for convert the column HourMil to the string representation.
SELECT SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),1,2)+':'+SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),3,2) FROM MYTABLE
but I think this code can be improved.