get_the_time

The timeline below displays how wordpress function get_the_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 written.
 *
 * @since 1.5.0
 *
 * @param string      $format Optional. Format to use for retrieving the time the post
 *                            was written. Accepts 'G', 'U', or PHP date format.
 *                            Defaults to the 'time_format' option.
 * @param int|WP_Post $post   Post ID or post object. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_the_time($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $the_time = get_post_time($_format, false, $post, true);
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string|int  $the_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 written. Accepts 'G', 'U', or PHP date format.
     * @param WP_Post     $post     Post object.
     */
    return apply_filters('get_the_time', $the_time, $format, $post);
}

WordPress Version: 5.6

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $format Optional. Format to use for retrieving the time the post
 *                            was written. Accepts 'G', 'U', or PHP date format.
 *                            Defaults to the 'time_format' option.
 * @param int|WP_Post $post   WP_Post object or ID. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_the_time($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $the_time = get_post_time($_format, false, $post, true);
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $format   Format to use for retrieving the time the post
     *                              was written. Accepts 'G', 'U', or PHP date format.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $format, $post);
}

WordPress Version: 5.1

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $format Optional. Format to use for retrieving the time the post
 *                            was written. Either 'G', 'U', or PHP date format defaults
 *                            to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post   WP_Post object or ID. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_the_time($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('time_format');
    $the_time = get_post_time($_format, false, $post, true);
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $format   Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or PHP date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $format, $post);
}

WordPress Version: 5.5

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $format Optional. Format to use for retrieving the time the post
 *                            was written. Either 'G', 'U', or PHP date format defaults
 *                            to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post   WP_Post object or ID. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_the_time($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' === $format) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($format, false, $post, true);
    }
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $format   Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or PHP date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $format, $post);
}

WordPress Version: 5.4

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $format Optional. Format to use for retrieving the time the post
 *                            was written. Either 'G', 'U', or PHP date format defaults
 *                            to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post   WP_Post object or ID. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
 *                          False on failure.
 */
function get_the_time($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $format) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($format, false, $post, true);
    }
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $format   Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or PHP date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $format, $post);
}

WordPress Version: 5.3

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object.
 * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 5.1

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
 * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 4.6

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
 * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filters the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 4.1

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
 * @return false|string Formatted date string or Unix timestamp. False on failure.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filter the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 4.0

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filter the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 3.9

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string      $d    Optional. Format to use for retrieving the time the post
 *                          was written. Either 'G', 'U', or php date format defaults
 *                          to the value specified in the time_format option. Default empty.
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
 * @return string|int Formatted date string, or Unix timestamp.
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    /**
     * Filter the time a post was written.
     *
     * @since 1.5.0
     *
     * @param string      $the_time The formatted time.
     * @param string      $d        Format to use for retrieving the time the post was written.
     *                              Accepts 'G', 'U', or php date format value specified
     *                              in 'time_format' option. Default empty.
     * @param int|WP_Post $post     WP_Post object or ID.
     */
    return apply_filters('get_the_time', $the_time, $d, $post);
}

WordPress Version: 3.7

/**
 * Retrieve the time at which the post was written.
 *
 * @since 1.5.0
 *
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
 * @param int|object $post Optional post ID or object. Default is global $post object.
 * @return string
 */
function get_the_time($d = '', $post = null)
{
    $post = get_post($post);
    if ('' == $d) {
        $the_time = get_post_time(get_option('time_format'), false, $post, true);
    } else {
        $the_time = get_post_time($d, false, $post, true);
    }
    return apply_filters('get_the_time', $the_time, $d, $post);
}