Title: WP_REST_Posts_Controller::prepare_date_response
Published: December 6, 2016
Last modified: February 24, 2026

---

# WP_REST_Posts_Controller::prepare_date_response( string $date_gmt, string|null $date = null ): string|null

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response/?output_format=md#changelog)

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

Checks the post_date_gmt or modified_gmt and prepare any post or modified date for
single post output.

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

 `$date_gmt`stringrequired

GMT publication time.

`$date`string|nulloptional

Local publication time.

Default:`null`

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

 string|null ISO8601/RFC3339 formatted datetime.

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

    ```php
    protected function prepare_date_response( $date_gmt, $date = null ) {
    	// Use the date if passed.
    	if ( isset( $date ) ) {
    		return mysql_to_rfc3339( $date );
    	}

    	// Return null if $date_gmt is empty/zeros.
    	if ( '0000-00-00 00:00:00' === $date_gmt ) {
    		return null;
    	}

    	// Return the formatted datetime.
    	return mysql_to_rfc3339( $date_gmt );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1259)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1259-L1272)

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

| Uses | Description | 
| [mysql_to_rfc3339()](https://developer.wordpress.org/reference/functions/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).

  |

| Used by | Description | 
| [WP_REST_Posts_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Prepares a single post output for response.

  |

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

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

## User Contributed Notes

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