Convert Military time to string representation
Posted
by RRUZ
on Stack Overflow
See other posts from Stack Overflow
or by RRUZ
Published on 2010-06-08T22:08:53Z
Indexed on
2010/06/08
22:12 UTC
Read the original article
Hit count: 204
sql
|sql-server
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.
© Stack Overflow or respective owner