WordPress at a glance

mysql2date() WP 1.0

Convert given date string into a different format.

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

Works based on: date_i18n()
✈ 1 time = 0.00018s = fast | 50000 times = 4.42s = fast

No Hooks.

Return

String/Int/true/false. Formatted date string or Unix timestamp. False if $date is empty.

Usage

mysql2date( $format, $date, $translate );
$format(string) (required)
Format of the date to return.
$date(string) (required)
Date string to convert.
$translate(true/false)
Whether the return date should be translated.
Default: true

Code of mysql2date: wp-includes/functions.php VER 4.9.8

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

Related Functions

From tag: date time

No comments
    Hello, !     Log In . Register