WordPress get_the_date() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Returns a date

Definition

In WordPress, get_the_date() returns the publish date of a post as a string. It does not print, so you can store it or use it inside other code.

Unlike the_date(), it gives you the date every time, even when two posts share the same day.

Syntax

A few ways to call get_the_date().

WordPress
<?php
echo get_the_date( 'F j, Y' );
CallWhat it does
get_the_date()Date in the format from Settings > General.
get_the_date( 'F j, Y' )Date in your own format.
get_the_date( 'Y-m-d', 12 )Date of the post with ID 12.
get_the_date( 'c' )Date in ISO 8601 format, good for the datetime attribute.

It returns the date. Use echo to print it. The format letters are the same as the PHP date() function.

Full declaration
WordPress
get_the_date( string $format = '', int|WP_Post $post = null ): string|int|false

Parameters

ParameterDescription
$formatstring. A PHP date format. Default is empty, which uses the 'Date Format' setting.
$postint|WP_Post. The post ID or object. Default is the current post.

Return Value

Return ValueDescription
stringThe formatted date.
intA timestamp, when the format is U or G.
falseIf the post cannot be found.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Show the publish date

Print the date of the current post in a clear format.

WordPress
<p>Published on <?php echo esc_html( get_the_date( 'F j, Y' ) ); ?></p>

How It Works

  1. get_the_date( 'F j, Y' ) returns the date as text.
  2. echo prints it.
  3. esc_html() keeps the output safe.

Example 2 — Use it in a time tag

Give browsers a machine date and show a nice date to readers.

WordPress
<time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>">
  <?php echo esc_html( get_the_date() ); ?>
</time>

How It Works

  1. The format c gives an ISO 8601 date for the datetime attribute.
  2. With no format, the site setting is used for the readable date.
  3. Both calls are for the same post.

Example 3 — Get the date of another post

Pass a post ID to read a different post.

WordPress
<?php
$date = get_the_date( 'M j, Y', 42 );
echo 'Post 42 was published on ' . esc_html( $date );

How It Works

  1. The second argument is the post ID.
  2. You do not need The Loop for this call.
  3. The date is returned, then joined with text.

Frequently Asked Questions

It returns the publish date of a post as a string, using a format you choose.
get_the_date() returns the date every time. the_date() prints, and only once per day in a loop.
Use get_the_modified_date(), or the_modified_date() to print it.
The same letters as the PHP date() function, for example F j, Y or Y-m-d.
Not if you pass a post ID. Without one it uses the current post.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful