WordPress the_date_xml() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints YYYY-MM-DD

Definition

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()).

Syntax

A few ways to call the_date_xml().

WordPress
<?php
the_date_xml();
CallWhat 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().

Full declaration
WordPress
the_date_xml(): void

Parameters

ParameterDescription
(none)This function takes no parameters.

Return Value

Return ValueDescription
voidNothing is returned. The date is printed.

WordPress Examples

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

Example 1 — Print the date

Print the date in YYYY-MM-DD format.

WordPress
<p>Date: <?php the_date_xml(); ?></p>

How It Works

  1. the_date_xml() prints the post date as YYYY-MM-DD.
  2. It needs no arguments.
  3. It uses the date when the post was published.

Example 2 — Use it in a time tag

Use it for the datetime attribute.

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

How It Works

  1. Browsers and search engines can read the datetime value.
  2. Readers see the friendly date.
  3. get_the_date() is used for the readable text.

Example 3 — Compare with get_the_date()

The same result can come from get_the_date( 'Y-m-d' ).

WordPress
<?php
the_date_xml();
echo "\n";
echo get_the_date( 'Y-m-d' );

How It Works

  1. the_date_xml() prints the date itself.
  2. get_the_date( 'Y-m-d' ) returns the same text.
  3. Use the second one when you need a different format later.

Frequently Asked Questions

It prints the post date in YYYY-MM-DD format.
No. Use get_the_date() with your own format instead.
No. It prints the date every time you call it.
No.
In the datetime attribute of a time tag, or in simple feeds.

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.

10 people found this page helpful