Convert MySQL Datetime to Custom Format in PHP
Converting a datetime column in MySQL to a specific display format can be achieved effortlessly with PHP. Here's how to transform your datetime data into the desired format of "mm/dd/yy H:M (AM/PM)":
$timestamp = strtotime($mysqlDatetime); $formattedDate = date('m/d/y g:i A', $timestamp);
In this code, $mysqlDatetime represents your original datetime value stored in MySQL. The strtotime() function converts the MySQL datetime string to a UNIX timestamp, which is then used in the date() function to format the datetime according to the desired format specification.
The format specification "m/d/y g:i A" translates to the following:
The above is the detailed content of How to Format MySQL Datetime as 'mm/dd/yy H:M (AM/PM)' in PHP?. For more information, please follow other related articles on the PHP Chinese website!