WordPress get_the_date() Function

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().
<?php
echo get_the_date( 'F j, Y' );
| Call | What 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
get_the_date( string $format = '', int|WP_Post $post = null ): string|int|false
Parameters
| Parameter | Description |
|---|
$format | string. A PHP date format. Default is empty, which uses the 'Date Format' setting. |
$post | int|WP_Post. The post ID or object. Default is the current post. |
Return Value
| Return Value | Description |
|---|
| string | The formatted date. |
| int | A timestamp, when the format is U or G. |
| false | If 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.
<p>Published on <?php echo esc_html( get_the_date( 'F j, Y' ) ); ?></p>
<p>Published on November 12, 2026</p>
How It Works
get_the_date( 'F j, Y' ) returns the date as text.echo prints it.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.
<time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>">
<?php echo esc_html( get_the_date() ); ?>
</time>
<time datetime="2026-11-12T09:45:00+05:30">
November 12, 2026
</time>
How It Works
- The format
c gives an ISO 8601 date for the datetime attribute. - With no format, the site setting is used for the readable date.
- Both calls are for the same post.
Example 3 — Get the date of another post
Pass a post ID to read a different post.
<?php
$date = get_the_date( 'M j, Y', 42 );
echo 'Post 42 was published on ' . esc_html( $date );
Post 42 was published on Aug 22, 2025
How It Works
- The second argument is the post ID.
- You do not need The Loop for this call.
- 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
Developer, cloud engineer, and technical writer
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