mysql2date( string $format, string $date, bool $translate = true )

Convert given date string into a different format.


Description Description

$format should be either a PHP date format string, e.g. ‘U’ for a Unix timestamp, or ‘G’ for a Unix timestamp assuming that $date is GMT.

If $translate is true then the given date and format string will be passed to date_i18n() for translation.


Parameters Parameters

$format

(string) (Required) Format of the date to return.

$date

(string) (Required) Date string to convert.

$translate

(bool) (Optional) Whether the return date should be translated.

Default value: true


Top ↑

Return Return

(string|int|bool) Formatted date string or Unix timestamp. False if $date is empty.


Top ↑

Source 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 );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
0.71 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.