get_post_modified_time

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

WordPress Version: 6.1

/**
 * Retrieves the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $format    Optional. Format to use for retrieving the time the post
 *                               was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      Post ID or post object. Default is global `$post` object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_post_modified_time($format = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $source = $gmt ? 'gmt' : 'local';
    $datetime = get_post_datetime($post, 'modified', $source);
    if (false === $datetime) {
        return false;
    }
    if ('U' === $format || 'G' === $format) {
        $time = $datetime->getTimestamp();
        // Returns a sum of timestamp with timezone offset. Ideally should never be used.
        if (!$gmt) {
            $time += $datetime->getOffset();
        }
    } elseif ($translate) {
        $time = wp_date($format, $datetime->getTimestamp(), $gmt ? new DateTimeZone('UTC') : null);
    } else {
        if ($gmt) {
            $datetime = $datetime->setTimezone(new DateTimeZone('UTC'));
        }
        $time = $datetime->format($format);
    }
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string|int $time   Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
     * @param string     $format Format to use for retrieving the time the post was modified.
     *                           Accepts 'G', 'U', or PHP date format. Default 'U'.
     * @param bool       $gmt    Whether to retrieve the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $format, $gmt);
}

WordPress Version: 5.6

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $format    Optional. Format to use for retrieving the time the post
 *                               was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global `$post` object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_post_modified_time($format = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $source = $gmt ? 'gmt' : 'local';
    $datetime = get_post_datetime($post, 'modified', $source);
    if (false === $datetime) {
        return false;
    }
    if ('U' === $format || 'G' === $format) {
        $time = $datetime->getTimestamp();
        // Returns a sum of timestamp with timezone offset. Ideally should never be used.
        if (!$gmt) {
            $time += $datetime->getOffset();
        }
    } elseif ($translate) {
        $time = wp_date($format, $datetime->getTimestamp(), $gmt ? new DateTimeZone('UTC') : null);
    } else {
        if ($gmt) {
            $datetime = $datetime->setTimezone(new DateTimeZone('UTC'));
        }
        $time = $datetime->format($format);
    }
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string|int $time   Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
     * @param string     $format Format to use for retrieving the time the post was modified.
     *                           Accepts 'G', 'U', or PHP date format. Default 'U'.
     * @param bool       $gmt    Whether to retrieve the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $format, $gmt);
}

WordPress Version: 5.4

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $format    Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or PHP date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global `$post` object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_post_modified_time($format = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $source = $gmt ? 'gmt' : 'local';
    $datetime = get_post_datetime($post, 'modified', $source);
    if (false === $datetime) {
        return false;
    }
    if ('U' === $format || 'G' === $format) {
        $time = $datetime->getTimestamp();
        // Returns a sum of timestamp with timezone offset. Ideally should never be used.
        if (!$gmt) {
            $time += $datetime->getOffset();
        }
    } elseif ($translate) {
        $time = wp_date($format, $datetime->getTimestamp(), $gmt ? new DateTimeZone('UTC') : null);
    } else {
        if ($gmt) {
            $datetime = $datetime->setTimezone(new DateTimeZone('UTC'));
        }
        $time = $datetime->format($format);
    }
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time   The formatted time.
     * @param string $format Format to use for retrieving the time the post was modified.
     *                       Accepts 'G', 'U', or PHP date format. Default 'U'.
     * @param bool   $gmt    Whether to retrieve the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $format, $gmt);
}

WordPress Version: 5.3

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $d         Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global `$post` object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $source = $gmt ? 'gmt' : 'local';
    $datetime = get_post_datetime($post, 'modified', $source);
    if (false === $datetime) {
        return false;
    }
    if ('U' === $d || 'G' === $d) {
        $time = $datetime->getTimestamp();
        // Returns a sum of timestamp with timezone offset. Ideally should never be used.
        if (!$gmt) {
            $time += $datetime->getOffset();
        }
    } elseif ($translate) {
        $time = wp_date($d, $datetime->getTimestamp(), $gmt ? new DateTimeZone('UTC') : null);
    } else {
        if ($gmt) {
            $datetime = $datetime->setTimezone(new DateTimeZone('UTC'));
        }
        $time = $datetime->format($d);
    }
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    Format to use for retrieving the time the post was modified.
     *                     Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to retrieve the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 5.1

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $d         Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to return the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 4.6

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $d         Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    /**
     * Filters the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to return the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 4.1

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $d         Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return false|string Formatted date string or Unix timestamp. False on failure.
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    /**
     * Filter the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to return the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 4.0

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string      $d         Optional. Format to use for retrieving the time the post
 *                               was modified. Either 'G', 'U', or php date format. Default 'U'.
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
 * @param bool        $translate Whether to translate the time string. Default false.
 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    /**
     * Filter the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to return the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 3.9

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
 * @param int|object $post Optional, default is global post object. A post_id or post object
 * @param bool $translate Optional, default is false. Whether to translate the result
 * @return string Returns timestamp
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    /**
     * Filter the localized time a post was last modified.
     *
     * @since 2.8.0
     *
     * @param string $time The formatted time.
     * @param string $d    The date format. Accepts 'G', 'U', or php date format. Default 'U'.
     * @param bool   $gmt  Whether to return the GMT time. Default false.
     */
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}

WordPress Version: 3.7

/**
 * Retrieve the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
 * @param int|object $post Optional, default is global post object. A post_id or post object
 * @param bool $translate Optional, default is false. Whether to translate the result
 * @return string Returns timestamp
 */
function get_post_modified_time($d = 'U', $gmt = false, $post = null, $translate = false)
{
    $post = get_post($post);
    if ($gmt) {
        $time = $post->post_modified_gmt;
    } else {
        $time = $post->post_modified;
    }
    $time = mysql2date($d, $time, $translate);
    return apply_filters('get_post_modified_time', $time, $d, $gmt);
}