Convert from MySQL datetime to another format with PHP

后端 未结 18 1191
醉话见心
醉话见心 2020-11-22 01:08

I have a datetime column in MySQL.

How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP?

18条回答
  •  无人共我
    2020-11-22 01:24

    To convert a date retrieved from MySQL into the format requested (mm/dd/yy H:M (AM/PM)):

    // $datetime is something like: 2014-01-31 13:05:59
    $time = strtotime($datetimeFromMysql);
    $myFormatForView = date("m/d/y g:i A", $time);
    // $myFormatForView is something like: 01/31/14 1:05 PM
    

    Refer to the PHP date formatting options to adjust the format.

提交回复
热议问题