Title: wp_date
Published: November 12, 2019
Last modified: August 20, 2026

---

# wp_date( string $format, int|null $timestamp = null, DateTimeZone|null $timezone = null ): string|false

## In this article

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

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

Retrieves the date, in localized format.

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

This is a newer function, intended to replace `date_i18n()` without legacy quirks
in it.

Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not
summed with timezone offset.

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

 `$format`stringrequired

PHP date format.

`$timestamp`int|nulloptional

Unix timestamp. Defaults to current time.

Default:`null`

`$timezone`DateTimeZone|nulloptional

Timezone to output result in. Defaults to timezone from site settings.

Default:`null`

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

 string|false The date, translated if locale specifies it. False on invalid timestamp
input.

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

    ```php
    function wp_date( $format, $timestamp = null, $timezone = null ) {
    	global $wp_locale;

    	if ( null === $timestamp ) {
    		$timestamp = time();
    	} elseif ( ! is_numeric( $timestamp ) ) {
    		return false;
    	}

    	if ( ! $timezone ) {
    		$timezone = wp_timezone();
    	}

    	$datetime = date_create( '@' . $timestamp );
    	$datetime->setTimezone( $timezone );

    	if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
    		$date = $datetime->format( $format );
    	} else {
    		// We need to unpack shorthand `r` format because it has parts that might be localized.
    		$format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format );

    		$new_format    = '';
    		$format_length = strlen( $format );
    		$month         = $wp_locale->get_month( $datetime->format( 'm' ) );
    		$weekday       = $wp_locale->get_weekday( $datetime->format( 'w' ) );

    		for ( $i = 0; $i < $format_length; $i++ ) {
    			switch ( $format[ $i ] ) {
    				case 'D':
    					$new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' );
    					break;
    				case 'F':
    					$new_format .= addcslashes( $month, '\\A..Za..z' );
    					break;
    				case 'l':
    					$new_format .= addcslashes( $weekday, '\\A..Za..z' );
    					break;
    				case 'M':
    					$new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), '\\A..Za..z' );
    					break;
    				case 'a':
    					$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), '\\A..Za..z' );
    					break;
    				case 'A':
    					$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), '\\A..Za..z' );
    					break;
    				case '\\':
    					$new_format .= $format[ $i ];

    					// If character follows a slash, we add it without translating.
    					if ( $i < $format_length ) {
    						$new_format .= $format[ ++$i ];
    					}
    					break;
    				default:
    					$new_format .= $format[ $i ];
    					break;
    			}
    		}

    		$date = $datetime->format( $new_format );
    		$date = wp_maybe_decline_date( $date, $format );
    	}

    	/**
    	 * Filters the date formatted based on the locale.
    	 *
    	 * @since 5.3.0
    	 *
    	 * @param string       $date      Formatted date string.
    	 * @param string       $format    Format to display the date.
    	 * @param int          $timestamp Unix timestamp.
    	 * @param DateTimeZone $timezone  Timezone.
    	 */
    	$date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone );

    	return $date;
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_date’, string $date, string $format, int $timestamp, DateTimeZone $timezone )](https://developer.wordpress.org/reference/hooks/wp_date/)

Filters the date formatted based on the locale.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_date/?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.

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

Determines if the date should be declined.

  | 
| [WP_Locale::get_month()](https://developer.wordpress.org/reference/classes/wp_locale/get_month/)`wp-includes/class-wp-locale.php` |

Retrieves the full translated month by month number.

  | 
| [WP_Locale::get_month_abbrev()](https://developer.wordpress.org/reference/classes/wp_locale/get_month_abbrev/)`wp-includes/class-wp-locale.php` |

Retrieves translated version of month abbreviation string.

  | 
| [WP_Locale::get_meridiem()](https://developer.wordpress.org/reference/classes/wp_locale/get_meridiem/)`wp-includes/class-wp-locale.php` |

Retrieves translated version of meridiem string.

  | 
| [WP_Locale::get_weekday()](https://developer.wordpress.org/reference/classes/wp_locale/get_weekday/)`wp-includes/class-wp-locale.php` |

Retrieves the full translated weekday word.

  | 
| [WP_Locale::get_weekday_abbrev()](https://developer.wordpress.org/reference/classes/wp_locale/get_weekday_abbrev/)`wp-includes/class-wp-locale.php` |

Retrieves the translated weekday abbreviation.

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

Calls the callback functions that have been added to a filter hook.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#)

| Used by | Description | 
| [WP_Debug_Data::get_wp_server()](https://developer.wordpress.org/reference/classes/wp_debug_data/get_wp_server/)`wp-admin/includes/class-wp-debug-data.php` |

Gets the WordPress server section of the debug data.

  | 
| [WP_Sitemaps_Posts::get_url_list()](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/)`wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php` |

Gets a URL list for a post type sitemap.

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

Retrieves the localized time of the post.

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

Retrieves the time at which the post was last modified.

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

Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds.

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

Converts given MySQL date string into a different format.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#)

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

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

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

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#comment-content-5536)
 2.    [Cameron Jones](https://profiles.wordpress.org/cameronjonesweb/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_date/#comment-5536)
 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%2Fwp_date%2F%23comment-5536)
     Vote results for this note: 2[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%2Fwp_date%2F%23comment-5536)
 4.  Useful background information: [https://make.wordpress.org/core/2019/09/23/date-time-improvements-wp-5-3/](https://make.wordpress.org/core/2019/09/23/date-time-improvements-wp-5-3/)
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_date%2F%3Freplytocom%3D5536%23feedback-editor-5536)
 6.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#comment-content-5820)
 7.    [Luiz Bills](https://profiles.wordpress.org/luizbills/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/wp_date/#comment-5820)
 8.  [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%2Fwp_date%2F%23comment-5820)
     Vote results for this note: 2[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%2Fwp_date%2F%23comment-5820)
 9.  PHP Date Formats: [https://www.php.net/manual/en/datetime.format.php#refsect1-datetime.format-parameters](https://www.php.net/manual/en/datetime.format.php#refsect1-datetime.format-parameters)
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_date%2F%3Freplytocom%3D5820%23feedback-editor-5820)
 11.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#comment-content-5071)
 12.   [Marc Heatley](https://profiles.wordpress.org/barkerbaggies/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_date/#comment-5071)
 13. [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%2Fwp_date%2F%23comment-5071)
     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%2Fwp_date%2F%23comment-5071)
 14. To get a translatable `the_date();` equivalent, you will need:
 15.     ```php
         echo wp_date( get_option( 'date_format' ), get_post_timestamp() ); ?>
         ```
     
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_date%2F%3Freplytocom%3D5071%23feedback-editor-5071)
 17.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#comment-content-6552)
 18.   [Rahi Saiful](https://profiles.wordpress.org/rahi6039/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_date/#comment-6552)
 19. [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%2Fwp_date%2F%23comment-6552)
     Vote results for this note: 0[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%2Fwp_date%2F%23comment-6552)
 20. **To get the date and time from the timestamp you can use this code**
 21.     ```php
         $dateTimeFormat = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
         echo wp_date( $dateTimeFormat, get_post_timestamp() );
         ```
     
 22. _You can use your own timestamp instead of [get\_post\_timestamp()](https://developer.wordpress.org/reference/functions/get_post_timestamp/)_
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_date%2F%3Freplytocom%3D6552%23feedback-editor-6552)
 24.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/wp_date/?output_format=md#comment-content-5070)
 25.   [Marc Heatley](https://profiles.wordpress.org/barkerbaggies/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_date/#comment-5070)
 26. [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%2Fwp_date%2F%23comment-5070)
     Vote results for this note: -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%2Fwp_date%2F%23comment-5070)
 27. Be aware that this function **returns** a date, but not echoes it.
 28. When I picked it up my muscle memory told me
 29.  * `wp_date();` would echo
      * and something like `get_wp_date();` would just return
 30. I _think_ the reason is becase it’s a drop-in replacement for PHP’s `date();` 
     not WordPress’ `the_date();`
 31.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_date%2F%3Freplytocom%3D5070%23feedback-editor-5070)

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