Example 1 — Print the date
Print the date in YYYY-MM-DD format.
<p>Date: <?php the_date_xml(); ?></p> How It Works
the_date_xml()prints the post date asYYYY-MM-DD.- It needs no arguments.
- It uses the date when the post was published.

In WordPress, the_date_xml() prints the post date in the format YYYY-MM-DD. This is a simple, machine friendly date, such as 2026-11-12.
It takes no arguments, and it prints the date every time (unlike the_date()).
A few ways to call the_date_xml().
<?php
the_date_xml(); | Call | What it does |
|---|---|
the_date_xml() | Print the date as YYYY-MM-DD. |
get_the_date( 'Y-m-d' ) | Return the same date as a string. |
It prints the date and takes no arguments. For another format, use the_time() or get_the_date().
the_date_xml(): void | Parameter | Description |
|---|---|
(none) | This function takes no parameters. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The date is printed. |
Three short examples. Each one shows the code and what it prints.
Print the date in YYYY-MM-DD format.
<p>Date: <?php the_date_xml(); ?></p> the_date_xml() prints the post date as YYYY-MM-DD.Use it for the datetime attribute.
<time datetime="<?php the_date_xml(); ?>">
<?php echo esc_html( get_the_date() ); ?>
</time> datetime value.get_the_date() is used for the readable text.The same result can come from get_the_date( 'Y-m-d' ).
<?php
the_date_xml();
echo "\n";
echo get_the_date( 'Y-m-d' ); the_date_xml() prints the date itself.get_the_date( 'Y-m-d' ) returns the same text.Open the functions index for simple guides with examples and FAQs.
10 people found this page helpful