Codex

Template Tags/the date

Contents

Description

Displays or returns the date of a post, or a set of posts if published on the same day.

SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() with a date-specific format string.

This tag must be used within The Loop.

Usage

 <?php the_date$format$before$after$echo ); ?> 

Parameters

$format
(string) (optional) The format for the date. Defaults to the date format configured in your WordPress options. See Formatting Date and Time.
Default: F j, Y)
$before
(string) (optional) Text to place before the date.
Default: None
$after
(string) (optional) Text to place after the date
Default: None
$echo
(boolean) (optional) Display the date (TRUE), or return the date to be used in PHP (FALSE).
Default: TRUE

Examples

Default Usage

Displays the date using defaults.

<p>Date posted: <?php the_date(); ?></p>

Date as Year, Month, Date in Heading

Displays the date using the '2007-07-23' format (ex: 2004-11-30), inside an <h2> tag.

<?php the_date('Y-m-d', '<h2>', '</h2>'); ?>

Date in Heading Using $my_date Variable

Returns the date in the default format inside an <h2> tag and assigns it to the $my_date variable. The variable's value is then displayed with the PHP echo command.

<?php $my_date = the_date('', '', '', FALSE); echo $my_date; ?>

Notes

Related

the_time, the_date, the_date_xml, the_modified_time, the_modified_date, the_modified_author, single_month_title, get_the_time, get_day_link, get_month_link, get_year_link, get_calendar

See also index of Function Reference and index of Template Tags.