mysql_to_rfc3339() WordPress Function

The mysql_to_rfc3339() function is used to convert a date from MySQL format to RFC 3339 format. This is useful when you need to convert a date from a database into a format that can be used in an XML or JSON document.

mysql_to_rfc3339( string $date_string ) #

Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s).


Description

Explicitly strips timezones, as datetimes are not saved with any timezone information. Including any information on the offset could be misleading.

Despite historical function name, the output does not conform to RFC3339 format, which must contain timezone.


Top ↑

Parameters

$date_string

(string)(Required)Date string to parse and format.


Top ↑

Return

(string) Date formatted for ISO8601 without time zone.


Top ↑

Source

File: wp-includes/functions.php

function mysql_to_rfc3339( $date_string ) {
	return mysql2date( 'Y-m-d\TH:i:s', $date_string, false );
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More