mysql2date( string $format, string $date, bool $translate = true )
Converts given MySQL date string into a different format.
Description
$format
should be a PHP date format string.- ‘U’ and ‘G’ formats will return an integer sum of timestamp with timezone offset.
$date
is expected to be local time in MySQL format (Y-m-d H:i:s
).
Historically UTC time could be passed to the function to produce Unix timestamp.
If $translate
is true then the given date and format string will be passed to wp_date()
for translation.
Parameters
- $format
-
(Required) Format of the date to return.
- $date
-
(Required) Date string to convert.
- $translate
-
(Optional) Whether the return date should be translated.
Default value: true
Return
(string|int|false) Integer if $format
is 'U' or 'G', string otherwise.<br> False on failure.
Source
File: wp-includes/functions.php
function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) )
return false;
if ( 'G' == $format )
return strtotime( $date . ' +0000' );
$i = strtotime( $date );
if ( 'U' == $format )
return $i;
if ( $translate )
return date_i18n( $format, $i );
else
return date( $format, $i );
}
Changelog
Version | Description |
---|---|
0.71 | Introduced. |