get_comment_date() WordPress Function

The get_comment_date() function retrieves the date on which a comment was made. The date is returned in the timezone set in the administration panel.

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

Retrieves the comment date of the current comment.


Parameters

$format

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

Default value: ''

$comment_ID

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


Top ↑

Return

(string) The comment's date.


Top ↑

More Information

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


Top ↑

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
VersionDescription
4.4.0Added the ability for $comment_ID to also accept a WP_Comment object.
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More