WordPress comment_date() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_date() prints the date when a comment was posted.

By default it uses the date format from Settings → General. You can pass a PHP date format to change it.

Syntax

Call it with no format for the site format, or pass a PHP date format.

WordPress
comment_date();
comment_date( 'd/m/Y' );
comment_date( 'F j, Y', 15 );
CallWhat it does
comment_date()Prints the date in the site's date format.
comment_date( 'd/m/Y' )Prints the date in your own format.
comment_date( 'F j, Y', 15 )Prints the date of comment 15.

Use comment_time() to print the time of the comment.

Full declaration
WordPress
comment_date( string $format = '', int|WP_Comment $comment_id = 0 ): void

Parameters

ParameterDescription
$formatOptional. A PHP date format. If empty, WordPress uses the date_format option.
$comment_idOptional. A comment ID or WP_Comment object. Default is the current comment.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the date.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Default date

Print the date in the site format.

WordPress
<span class="date"><?php comment_date(); ?></span>

How It Works

  1. No format is given.
  2. WordPress uses the date format from your settings.
  3. The date is printed as plain text.

Example 2 — Custom format

Print the date as day/month/year.

WordPress
<span class="date"><?php comment_date( 'd/m/Y' ); ?></span>

How It Works

  1. d is the day, m is the month, Y is the year.
  2. Use any PHP date format here.
  3. The format does not change your site settings.

Example 3 — Date and time together

Build a time tag with the date and the time.

WordPress
<time datetime="<?php echo esc_attr( get_comment_date( 'c' ) ); ?>">
  <?php comment_date(); ?> at <?php comment_time(); ?>
</time>

How It Works

  1. get_comment_date( 'c' ) returns a machine-readable date.
  2. comment_date() prints the friendly date.
  3. comment_time() prints the time.

Frequently Asked Questions

It prints the date when the current comment was posted.
Pass a PHP date format, such as 'd/m/Y', as the first argument.
From the Date Format setting in Settings, General.
Use get_comment_date().
Use comment_time().

Next: comment_excerpt()

Print a short plain-text excerpt of the current comment.

comment_excerpt() tutorial →

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