On this page
mysql2date( string $format, string $date, bool $translate = true ): string|int|false
Converts given MySQL date string into a different format.
Description
$formatshould be a PHP date format string.- ‘U’ and ‘G’ formats will return an integer sum of timestamp with timezone offset.
$dateis 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.
Parameters
$formatstring Required-
Format of the date to return.
$datestring Required-
Date string to convert.
$translatebool Optional-
Whether the return date should be translated.
Default:
true
Return
string|int|false Integer if $format is 'U' or 'G', string otherwise.
False on failure.
Source
File: wp-includes/functions.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_timezone() wp-includes/functions.php | Retrieves the timezone of the site as a |
| wp_date() wp-includes/functions.php | Retrieves the date, in localized format. |
Used By
| Used By | Description |
|---|---|
| WP_Query::generate_postdata() wp-includes/class-wp-query.php | Generate post data. |
| WP_Customize_Manager::save_changeset_post() wp-includes/class-wp-customize-manager.php | Saves the post for the loaded changeset. |
| wp_check_comment_flood() wp-includes/comment.php | Checks whether comment flooding is occurring. |
| mysql_to_rfc3339() wp-includes/functions.php | Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s). |
| WP_MS_Sites_List_Table::column_lastupdated() wp-admin/includes/class-wp-ms-sites-list-table.php | Handles the lastupdated column output. |
| WP_MS_Sites_List_Table::column_registered() wp-admin/includes/class-wp-ms-sites-list-table.php | Handles the registered column output. |
| WP_MS_Users_List_Table::column_registered() wp-admin/includes/class-wp-ms-users-list-table.php | Handles the registered date column output. |
| export_wp() wp-admin/includes/export.php | Generates the WXR export file for download. |
| get_inline_data() wp-admin/includes/template.php | Adds hidden fields with the data for use in the inline editor for posts and pages. |
| touch_time() wp-admin/includes/template.php | Prints out HTML form date elements for editing post or comment publish date. |
| get_media_item() wp-admin/includes/media.php | Retrieves HTML form for modifying the image attachment. |
| wp_ajax_wp_fullscreen_save_post() wp-admin/includes/ajax-actions.php | Ajax handler for saving posts from the fullscreen editor. |
| wp_ajax_find_posts() wp-admin/includes/ajax-actions.php | Ajax handler for querying posts for the Find Posts modal. |
| wp_get_archives() wp-includes/general-template.php | Displays archive links based on type and format. |
| the_date_xml() wp-includes/general-template.php | Outputs the date in iso8601 format for xml files. |
| get_boundary_post_rel_link() wp-includes/deprecated.php | Get boundary post relational link. |
| get_parent_post_rel_link() wp-includes/deprecated.php | Get parent post relational link. |
| WP::send_headers() wp-includes/class-wp.php | Sends additional HTTP headers for caching, content type, etc. |
| get_adjacent_post_link() wp-includes/link-template.php | Retrieves the adjacent post link. |
| get_adjacent_post_rel_link() wp-includes/link-template.php | Retrieves the adjacent post relational link. |
| Walker_Page::start_el() wp-includes/class-walker-page.php | Outputs the beginning of the current element in the tree. |
| wp_prepare_attachment_for_js() wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
| wpmu_validate_user_signup() wp-includes/ms-functions.php | Sanitizes and validates data required for a user sign-up. |
| wpmu_validate_blog_signup() wp-includes/ms-functions.php | Processes new site registrations. |
| wp_xmlrpc_server::wp_editPost() wp-includes/class-wp-xmlrpc-server.php | Edit a post for any registered post type. |
| wp_xmlrpc_server::_convert_date() wp-includes/class-wp-xmlrpc-server.php | Convert a WordPress date string to an IXR_Date object. |
| wp_xmlrpc_server::_convert_date_gmt() wp-includes/class-wp-xmlrpc-server.php | Convert a WordPress GMT date string to an IXR_Date object. |
| get_comment_time() wp-includes/comment-template.php | Retrieves the comment time of the current comment. |
| get_comment_date() wp-includes/comment-template.php | Retrieves the comment date of the current comment. |
| _WP_Editors::wp_link_query() wp-includes/class-wp-editor.php | Performs post queries for internal linking. |
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/mysql2date