Instruction:
<?php $date = mysql2date( $format, $date, $translate ); ?>
Parameter
PARAMETER | TYPE | DESCRIPTION | DEFAULT | REQUIRED |
$format | string | Output can be PHP date format or Unix timestamp. | no | yes |
$date | string | mysql2date() only recognizes “Ymd H:i:s” format, so the original timestamp string needs to be converted to this format. | no | yes |
$translate | boolean | If true, the specified date and format string will be passed to date_i18n() for translation into local date format. | yes | no |
Return value
String or integer, formatted date string, or Unix timestamp.
Examples
Convert MySQL date to Unix timestamp:
echo mysql2date( 'U', '2022-02-23 06:12:45' ); // 132977565
Convert MySQL date to another date format:
echo mysql2date ('l, F j, Y', '2012-02-23 06:12:45') // Thursday, February 23, 2022
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂