Title: get_date_from_gmt
Published: April 25, 2014
Last modified: May 20, 2026

---

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

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#description)󠁿

Requires a date in the Y-m-d H:i:s format.
Default return format of ‘Y-m-d H:i:s’
can be overridden using the `$format` parameter.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#parameters)󠁿

 `$date_string`stringrequired

The date to be converted, in UTC or GMT timezone.

`$format`stringoptional

The format string for the returned date. Default ‘Y-m-d H:i:s’.

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

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#return)󠁿

 string Formatted version of the date, in the site’s timezone.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#source)󠁿

    ```php
    function get_date_from_gmt( $date_string, $format = 'Y-m-d H:i:s' ) {
    	$datetime = date_create( $date_string, new DateTimeZone( 'UTC' ) );

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

    	return $datetime->setTimezone( wp_timezone() )->format( $format );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/formatting.php#L3692)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L3692-L3700)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_timezone()](https://developer.wordpress.org/reference/functions/wp_timezone/)`wp-includes/functions.php` |

Retrieves the timezone of the site as a `DateTimeZone` object.

  |

| Used by | Description | 
| [wp_resolve_post_date()](https://developer.wordpress.org/reference/functions/wp_resolve_post_date/)`wp-includes/post.php` |

Uses wp_checkdate to return a valid Gregorian-calendar value for post_date.

  | 
| [WP_Customize_Manager::save_changeset_post()](https://developer.wordpress.org/reference/classes/wp_customize_manager/save_changeset_post/)`wp-includes/class-wp-customize-manager.php` |

Saves the post for the loaded changeset.

  | 
| [rest_get_date_with_gmt()](https://developer.wordpress.org/reference/functions/rest_get_date_with_gmt/)`wp-includes/rest-api.php` |

Parses a date into both its local and UTC equivalent, in MySQL datetime format.

  | 
| [wp_xmlrpc_server::wp_editComment()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_editcomment/)`wp-includes/class-wp-xmlrpc-server.php` |

Edits a comment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.2.0](https://developer.wordpress.org/reference/since/1.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#comment-content-5119)
 2.    [d4mation](https://profiles.wordpress.org/d4mation/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_date_from_gmt/#comment-5119)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%23comment-5119)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%23comment-5119)
 4.  [get_date_from_gmt()](https://developer.wordpress.org/reference/functions/get_date_from_gmt/)
     does not accept a Unix Timestamp because date_create() doesn’t.
 5.  If you need to provide a Unix Timestamp, you will need to convert it to a different
     format first like the following example:
 6.      ```php
         <?php
     
         $utc_timestamp = 1623096269;
     
         // This is a format that date_create() will accept
         $utc_timestamp_converted = date( 'Y-m-d H:i:s', $utc_timestamp );
     
         $output_format = 'Y-m-d H:i:s';
     
         // Now we can use our timestamp with get_date_from_gmt()
         $local_timestamp = get_date_from_gmt( $utc_timestamp_converted, $output_format );
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%3Freplytocom%3D5119%23feedback-editor-5119)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_date_from_gmt/?output_format=md#comment-content-7048)
 9.    [Geoffrey Brossard](https://profiles.wordpress.org/geoffreybr/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/get_date_from_gmt/#comment-7048)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%23comment-7048)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%23comment-7048)
 11. The inverse function is [get_gmt_from_date](https://developer.wordpress.org/reference/functions/get_gmt_from_date/).
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F%3Freplytocom%3D7048%23feedback-editor-7048)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_date_from_gmt%2F)
before being able to contribute a note or feedback.