get_comment_date( string $d = '', int|WP_Comment $comment_ID )
Retrieve the comment date of the current comment.
Description Description
Parameters Parameters
- $d
-
(string) (Optional) The format of the date. Default user's setting.
Default value: ''
- $comment_ID
-
(int|WP_Comment) (Optional) WP_Comment or ID of the comment for which to get the date. Default current comment.
Return Return
(string) The comment's date.
Source Source
File: wp-includes/comment-template.php
function get_comment_date( $d = '', $comment_ID = 0 ) { $comment = get_comment( $comment_ID ); if ( '' == $d ) { $date = mysql2date( get_option( 'date_format' ), $comment->comment_date ); } else { $date = mysql2date( $d, $comment->comment_date ); } /** * Filters the returned comment date. * * @since 1.5.0 * * @param string|int $date Formatted date string or Unix timestamp. * @param string $d The format of the date. * @param WP_Comment $comment The comment object. */ return apply_filters( 'get_comment_date', $date, $d, $comment ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.4.0 | Added the ability for $comment_ID to also accept a WP_Comment object. |
1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
Examples of Different Date Formats
Display a beautiful, human-readable, comment time:
When called it will convert the time and return something like:
Use this function because it’s more user friendly.