get_comment_date( string $format = '', int|WP_Comment $comment_ID )

Retrieves the comment date of the current comment.

Parameters Parameters


(string) (Optional) PHP date format. Defaults to the 'date_format' option.

Default value: ''


(int|WP_Comment) (Optional) WP_Comment or ID of the comment for which to get the date. Default current comment.

Top ↑

Return Return

(string) The comment's date.

Top ↑

More Information More Information

The date format can be in a format specified in Formatting Date and Time

Top ↑

Source Source

File: wp-includes/comment-template.php

function get_comment_date( $format = '', $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );

	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );

	$date = mysql2date( $_format, $comment->comment_date );

	 * Filters the returned comment date.
	 * @since 1.5.0
	 * @param string|int $date    Formatted date string or Unix timestamp.
	 * @param string     $format  PHP date format.
	 * @param WP_Comment $comment The comment object.
	return apply_filters( 'get_comment_date', $date, $format, $comment );

Top ↑

Changelog Changelog

Version Description
4.4.0 Added the ability for $comment_ID to also accept a WP_Comment object.
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Andrei Surdu

    Display a beautiful, human-readable, comment time:

    function smk_get_comment_time( $comment_id = 0 ){
    	return sprintf( 
    		_x( '%s ago', 'Human-readable time', 'text-domain' ), 
    			get_comment_date( 'U', $comment_id ), 
    			current_time( 'timestamp' ) 

    When called it will convert the time and return something like:

    "1 min ago", "3 mins ago", "17 hours ago", "7 days ago", "2 weeks ago", etc....

    Use this function because it’s more user friendly.

  2. Skip to note 3 content
    Contributed by thelittlemercoder

    Examples of Different Date Formats

    // Prints something like: Monday 8th of August 2005
    echo get_comment_date( 'l jS \of F Y' );
    // Prints something like: Mon Mar 8 2012
    echo get_comment_date( 'D M j Y' );
    // Prints something like 07/08/2017 (dd/mm/yyyy)
    echo get_comment_date( 'd\/m\/Y' );

You must log in before being able to contribute a note or feedback.