Title: the_date
Published: April 25, 2014
Last modified: August 20, 2026

---

# the_date( string $format = '', string $before = '', string $after = '', bool $display = true ): string|null

## In this article

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

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

Displays or retrieves the date of the post (once per date).

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

Will only output the date if the current post’s date is different from the previous
one output.

i.e. Only one date listing will show per day worth of posts shown in the loop, even
if the function is called several times for each post.

HTML output can be filtered with [‘the_date’](https://developer.wordpress.org/reference/hooks/the_date/).

Date string output can be filtered with [‘get_the_date’](https://developer.wordpress.org/reference/hooks/get_the_date/).

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

 `$format`stringoptional

PHP date format. Defaults to the `'date_format'` option.

Default:`''`

`$before`stringoptional

Output before the date.

Default:`''`

`$after`stringoptional

Output after the date.

Default:`''`

`$display`booloptional

Whether to echo the date or return it.

Default:`true`

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

 string|null String if retrieving.

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

    ```php
    function the_date( $format = '', $before = '', $after = '', $display = true ) {
    	global $currentday, $previousday;

    	$the_date = '';

    	if ( is_new_day() ) {
    		$the_date    = $before . get_the_date( $format ) . $after;
    		$previousday = $currentday;
    	}

    	/**
    	 * Filters the date of the post, for display.
    	 *
    	 * @since 0.71
    	 *
    	 * @param string $the_date The formatted date string.
    	 * @param string $format   PHP date format.
    	 * @param string $before   HTML output before the date.
    	 * @param string $after    HTML output after the date.
    	 */
    	$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );

    	if ( $display ) {
    		echo $the_date;
    	} else {
    		return $the_date;
    	}
    }
    ```

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

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

 [apply_filters( ‘the_date’, string $the_date, string $format, string $before, string $after )](https://developer.wordpress.org/reference/hooks/the_date/)

Filters the date of the post, for display.

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

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

Retrieves the date of the post.

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

Determines whether the publish date of the current post in the loop is different from the publish date of the previous post in the loop.

  | 
| [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 1 more](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#)

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

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

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

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#comment-content-415)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_date/#comment-415)
 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%2Fthe_date%2F%23comment-415)
     Vote results for this note: 4[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%2Fthe_date%2F%23comment-415)
 4.  **Date as Year, Month, Date in Heading**
      Displays the date using the ‘2007-07-
     23’ format (ex: 2004-11-30), inside an <h2> tag.
 5.      ```php
         <?php the_date( 'Y-m-d', '<h2>', '</h2>' ); ?>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_date%2F%3Freplytocom%3D415%23feedback-editor-415)
 7.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#comment-content-414)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_date/#comment-414)
 9.  [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%2Fthe_date%2F%23comment-414)
     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%2Fthe_date%2F%23comment-414)
 10. **Default Usage**
      Displays the date using defaults.
 11.     ```php
         <?php the_date(); ?>
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_date%2F%3Freplytocom%3D414%23feedback-editor-414)
 13.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#comment-content-416)
 14.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_date/#comment-416)
 15. [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%2Fthe_date%2F%23comment-416)
     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%2Fthe_date%2F%23comment-416)
 16. **Date in Heading Using $my_date Variable**
      Returns the date in the default format
     inside an <h2> tag and assigns it to the `$my_date` variable. The variable’s value
     is then displayed with the PHP echo command.
 17.     ```php
         $my_date = the_date( '', '<h2>', '</h2>', false );
         echo $my_date;
         ```
     
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_date%2F%3Freplytocom%3D416%23feedback-editor-416)
 19.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#comment-content-4905)
 20.   [Ruhul Amin](https://profiles.wordpress.org/amihabibkhan/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/the_date/#comment-4905)
 21. [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%2Fthe_date%2F%23comment-4905)
     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%2Fthe_date%2F%23comment-4905)
 22. **As stated in the documentation if there are multiple posts from the same day,
     it will only show once.**
      To show the date for posts published under same day,
     we should use the template tag [the_time()](https://developer.wordpress.org/reference/functions/the_time/)
     or [get_the_date()](https://developer.wordpress.org/reference/functions/get_the_date/)
     with a date-specific format string.
 23.     ```php
         <?php echo get_the_date(); ?> 
         // get_the_date() return the date doesn't echo the date, so have to echo to show it
     
         // or use the_time() with date-specific format
         <?php the_time( 'd F Y' ); ?>
         ```
     
 24. Both functions takes an optional parameter which follows the PHP Date Format
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_date%2F%3Freplytocom%3D4905%23feedback-editor-4905)
 26.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/the_date/?output_format=md#comment-content-5475)
 27.   [Ibrahim khalil](https://profiles.wordpress.org/ikefti/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/the_date/#comment-5475)
 28. [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%2Fthe_date%2F%23comment-5475)
     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%2Fthe_date%2F%23comment-5475)
 29. //add a specific date format with your loop
 30. //example format: November 10, 2021. [here ](https://wordpress.org/support/article/formatting-date-and-time/#format-string-examples)
     You can see date Format String Examples::
 31.     ```php
         <?php the_time( 'F j, Y' );?>
         ```
     
 32.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_date%2F%3Freplytocom%3D5475%23feedback-editor-5475)

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