Use mysql2date to convert date string obtained from the database into a readable date

<?php $date = mysql2date( $format, $date, $translate ); ?>
$formatstringOutput can be PHP date format or Unix timestamp.noyes
$datestringmysql2date() only recognizes “Ymd H:i:s” format, so the original timestamp string needs to be converted to this format.noyes
$translatebooleanIf true, the specified date and format string will be passed to date_i18n() for translation into local date format.yesno

String or integer, formatted date string, or Unix timestamp.

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?

Leave a Reply