get_gmt_from_date( string $date_string, string $format = 'Y-m-d H:i:s' ): string

Given a date in the timezone of the site, returns that date in UTC.


Description

Requires and returns a date in the Y-m-d H:i:s format.
Return format can be overridden using the $format parameter.


Top ↑

Parameters

$date_string string Required
The date to be converted, in the timezone of the site.
$format string Optional
The format string for the returned date.

Default: 'Y-m-d H:i:s'


Top ↑

Return

string Formatted version of the date, in UTC.


Top ↑

Source

File: wp-includes/formatting.php. View all references

function get_gmt_from_date( $date_string, $format = 'Y-m-d H:i:s' ) {
	$datetime = date_create( $date_string, wp_timezone() );

	if ( false === $datetime ) {
		return gmdate( $format, 0 );
	}

	return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( $format );
}


Top ↑

Changelog

Changelog
Version Description
1.2.0 Introduced.

Top ↑

User Contributed Notes