Title: wp_resolve_post_date
Published: March 9, 2021
Last modified: February 24, 2026

---

# wp_resolve_post_date( string $post_date, string $post_date_gmt ): string|false

## In this article

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

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

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

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

If post_date is not provided, this first checks post_date_gmt if provided, then 
falls back to use the current time.

For back-compat purposes in wp_insert_post, an empty post_date and an invalid post_date_gmt
will continue to return ‘1970-01-01 00:00:00’ rather than false.

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

 `$post_date`stringrequired

The date in mysql format (`Y-m-d H:i:s`).

`$post_date_gmt`stringrequired

The GMT date in mysql format (`Y-m-d H:i:s`).

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

 string|false A valid Gregorian-calendar date string, or false on failure.

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

    ```php
    function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) {
    	// If the date is empty, set the date to now.
    	if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) {
    		if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) {
    			$post_date = current_time( 'mysql' );
    		} else {
    			$post_date = get_date_from_gmt( $post_date_gmt );
    		}
    	}

    	// Validate the date.
    	preg_match( '/^(\d{4})-(\d{1,2})-(\d{1,2})/', $post_date, $matches );

    	if ( empty( $matches ) || ! is_array( $matches ) || count( $matches ) < 4 ) {
    		return false;
    	}

    	$valid_date = wp_checkdate( $matches[2], $matches[3], $matches[1], $post_date );

    	if ( ! $valid_date ) {
    		return false;
    	}
    	return $post_date;
    }
    ```

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

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

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

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

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

Tests if the supplied date is valid for the Gregorian calendar.

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

Retrieves the current time based on specified type.

  |

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

Inserts or update a post.

  | 
| [wp_update_nav_menu_item()](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/)`wp-includes/nav-menu.php` |

Saves the properties of a menu item or create a new one.

  |

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

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

## User Contributed Notes

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