get_comment_date( string $format = , int|WP_Comment $comment_id ): string

Retrieves the comment date of the current comment.

Parameters

$formatstringoptional
PHP date format. Defaults to the 'date_format' option.

Default:''

$comment_idint|WP_Commentoptional
WP_Comment or ID of the comment for which to get the date.
Default current comment.

Return

string The comment’s date.

More Information

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

Source

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

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

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

	/**
	 * Filters the returned comment date.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $comment_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', $comment_date, $format, $comment );
}

Hooks

apply_filters( ‘get_comment_date’, string|int $comment_date, string $format, WP_Comment $comment )

Filters the returned comment date.

Changelog

VersionDescription
4.4.0Added the ability for $comment_id to also accept a WP_Comment object.
1.5.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    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' ), 
    		human_time_diff( 
    			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.

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