WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/mysql2date

Contents

Description

Converts given MySQL date string into a different format.

Usage

<?php $date mysql2date$format$date$translate ); ?>

Parameters

$format
(string) (required) The requested output 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.
Default: None
$date
(string) (required) the input string, this cannot be the raw time-stamp, it has to be converted into the following format first: 'Y-m-d H:i:s' . This is the only way mysql2date() will recognize your date.
Default: None
$translate
(boolean) (optional) If true then the given date and format string will be passed to date_i18n() for translation.
Default: true

Return Values

(string|integer) 
Formatted date string, or Unix timestamp.

Examples

Convert a MySQL date to a Unix timestamp:

echo mysql2date( 'U', '2012-02-23 06:12:45' ); // 1329977565

Convert a MySQL date to another date format:

echo mysql2date( 'l, F j, Y', '2012-02-23 06:12:45' ) // Thursday, February 23, 2012

Notes

Change Log

Since: 0.71

Source File

mysql2date() is located in wp-includes/functions.php

Related

Formatting Date and Time

See also index of Function Reference and index of Template Tags.