get_the_date( string $format, int|WP_Post $post = null ): string|int|false

Retrieves the date of the post.

Description

Unlike the_date() this function will always return the date.
Modify output with the ‘get_the_date’ filter.

Parameters

$formatstringoptional
PHP date format. Defaults to the 'date_format' option.
$postint|WP_Postoptional
Post ID or WP_Post object. Default current post.

Default:null

Return

string|int|false Date the current post was written. False on failure.

Source

function get_the_date( $format = '', $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );

	$the_date = get_post_time( $_format, false, $post, true );

	/**
	 * Filters the date of the post.
	 *
	 * @since 3.0.0
	 *
	 * @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
	 * @param string     $format   PHP date format.
	 * @param WP_Post    $post     The post object.
	 */
	return apply_filters( 'get_the_date', $the_date, $format, $post );
}

Hooks

apply_filters( ‘get_the_date’, string|int $the_date, string $format, WP_Post $post )

Filters the date of the post.

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 10 content
  2. Skip to note 16 content

    If you need the modified date for schema purpose in ISO format

    <?php echo get_the_modified_date( 'c' ); ?>

You must log in before being able to contribute a note or feedback.