Converting mysql TIME from 24 HR to AM/PM format

后端 未结 5 537
南旧
南旧 2020-12-17 14:37

I want to display the TIME field from my mysql table on my website, but rather than showing 21:00:00 etc I want to show 8:00 PM. I need a function/code to do this or even an

5条回答
  •  心在旅途
    2020-12-17 15:32

    Show the date & time data in AM/PM format with the following example...

    SELECT DATE_FORMAT(`t`.`date_field`,'%h:%i %p') AS `date_field` FROM `table_name` AS `t`
    

    OR

    SELECT DATE_FORMAT(`t`.`date_field`,'%r') AS `date_field` FROM `table_name` AS `t`
    

    Both are working properly.

提交回复
热议问题