Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/mysql2date


Converts given MySQL date string into a different format.


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


(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
(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
(boolean) (optional) If true then the given date and format string will be passed to date_i18n() for translation.
Default: true

Return Values

Formatted date string, or Unix timestamp.


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


Change Log

Since: 0.71

Source File

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


Formatting Date and Time

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