get_comment_time

The timeline below displays how wordpress function get_comment_time has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 * @since 6.2.0 Added the `$comment_id` parameter.
 *
 * @param string         $format     Optional. PHP date format. Defaults to the 'time_format' option.
 * @param bool           $gmt        Optional. Whether to use the GMT date. Default false.
 * @param bool           $translate  Optional. Whether to translate the time (for use in feeds).
 *                                   Default true.
 * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the time.
 *                                   Default current comment.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true, $comment_id = 0)
{
    $comment = get_comment($comment_id);
    if (null === $comment) {
        return '';
    }
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $comment_time = mysql2date($_format, $comment_date, $translate);
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $comment_time The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format       PHP date format.
     * @param bool       $gmt          Whether the GMT date is in use.
     * @param bool       $translate    Whether the time is translated.
     * @param WP_Comment $comment      The comment object.
     */
    return apply_filters('get_comment_time', $comment_time, $format, $gmt, $translate, $comment);
}

WordPress Version: 6.2

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 * @since 6.2.0 Added the `$comment_id` parameter.
 *
 * @param string         $format     Optional. PHP date format. Defaults to the 'time_format' option.
 * @param bool           $gmt        Optional. Whether to use the GMT date. Default false.
 * @param bool           $translate  Optional. Whether to translate the time (for use in feeds).
 *                                   Default true.
 * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the time.
 *                                   Default current comment.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true, $comment_id = 0)
{
    $comment = get_comment($comment_id);
    if (null === $comment) {
        return '';
    }
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $date = mysql2date($_format, $comment_date, $translate);
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    PHP date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 5.7

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $format    Optional. PHP time format. Defaults to the 'time_format' option.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $date = mysql2date($_format, $comment_date, $translate);
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    PHP date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 5.6

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $format    Optional. PHP date format. Defaults to the 'time_format' option.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $date = mysql2date($_format, $comment_date, $translate);
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    PHP date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 5.1

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $format    Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $date = mysql2date($_format, $comment_date, $translate);
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 5.5

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $format    Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' === $format) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($format, $comment_date, $translate);
    }
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 5.4

/**
 * Retrieves the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $format    Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($format = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $format) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($format, $comment_date, $translate);
    }
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $format    Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $format, $gmt, $translate, $comment);
}

WordPress Version: 4.6

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filters the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment);
}

WordPress Version: 4.4

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    $comment = get_comment();
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filter the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param WP_Comment $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment);
}

WordPress Version: 4.3

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @global object $comment
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    global $comment;
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filter the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param object     $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment);
}

WordPress Version: 3.9

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
 *                          Default true.
 * @return string The formatted time.
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    global $comment;
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filter the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         Date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     * @param object     $comment   The comment object.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment);
}

WordPress Version: 3.8

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds). Default true.
 * @return string The formatted time
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    global $comment;
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filter the returned comment time.
     *
     * @since 1.5.0
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         The date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate);
}

WordPress Version: 3.7

/**
 * Retrieve the comment time of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d         Optional. The format of the time. Default user's settings.
 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
 * @param bool   $translate Optional. Whether to translate the time (for use in feeds). Default true.
 * @return string The formatted time
 */
function get_comment_time($d = '', $gmt = false, $translate = true)
{
    global $comment;
    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    if ('' == $d) {
        $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    } else {
        $date = mysql2date($d, $comment_date, $translate);
    }
    /**
     * Filter the returned comment time.
     *
     * @since 1.5.2
     *
     * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     * @param string     $d         The date format.
     * @param bool       $gmt       Whether the GMT date is in use.
     * @param bool       $translate Whether the time is translated.
     */
    return apply_filters('get_comment_time', $date, $d, $gmt, $translate);
}