how to convert weird varchar “time” to real time in mysql?

前端 未结 5 752

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.

5条回答
  •  春和景丽
    2020-12-21 12:21

    This is a quick hack, but since you're missing the ":" between the 4 digits number how about inserting the missing colon.

    SELECT TIME_FORMAT( CONCAT( SUBSTRING('2359', 0, 2), ':', 
                                SUBSTRING('2359', 3, 2)), '%h:%i');
    

    Of course, replace the 2359 with the time column name.

提交回复
热议问题