mysql2date() – Convert given MySQL date string into a different format.

You appear to be a bot. Output may be restricted

Description

Convert given MySQL date string into a different format.

  • `$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.

Usage

$string|int|false = mysql2date( $format, $date, $translate );

Parameters

$format
( string ) required – Format of the date to return.
$date
( string ) required – Date string to convert.
$translate
( bool ) optional default: 1 – Whether the return date should be translated. Default true.

Returns

string|int|false Integer if $format is 'U' or 'G', string otherwise. False on failure.

Source

File name: wordpress/wp-includes/functions.php
Lines:

1 to 22 of 22
function mysql2date( $format, $date, $translate = true ) {
  if ( empty( $date ) ) {
    return false;
  }

  $datetime = date_create( $date, wp_timezone() );

  if ( false === $datetime ) {
    return false;
  }

  // Returns a sum of timestamp with timezone offset. Ideally should never be used.
  if ( 'G' === $format || 'U' === $format ) {
    return $datetime->getTimestamp() + $datetime->getOffset();
  }

  if ( $translate ) {
    return wp_date( $format, $datetime->getTimestamp() );
  }

  return $datetime->format( $format );
}
 

 View on GitHub View on Trac