I have a time value being stored in a database as a varchar(4) and I need to convert it to real time.
for example, if the time is \"23:59\" I want 11:59PM returned.
Using a table named test
with a column named string
and with values
2300
2100
1200
0430
0430
With query
select concat(time_format(concat(substring(string,-4,2),':',substring(string,3)),'%h:%i'),
case when string >= 1200 then ' PM' else ' AM' end)
from test;
You get,
11:00 PM
09:00 PM
12:00 PM
04:30 AM
04:30 AM