get_the_date

The timeline below displays how wordpress function get_the_date 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 date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param string      $format Optional. PHP date format. Defaults to the 'date_format' option.
 * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|int|false Date the current post was written. False on failure.
 */
function get_the_date($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('date_format');
    $the_date = get_post_time($_format, false, $post, true);
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string|int  $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
     * @param string      $format   PHP date format.
     * @param WP_Post     $post     The post object.
     */
    return apply_filters('get_the_date', $the_date, $format, $post);
}

WordPress Version: 5.6

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param string      $format Optional. PHP date format. Defaults to the 'date_format' option.
 * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|false Date the current post was written. False on failure.
 */
function get_the_date($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('date_format');
    $the_date = get_post_time($_format, false, $post, true);
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $format   PHP date format.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $format, $post);
}

WordPress Version: 5.1

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param string      $format Optional. PHP date format defaults to the date_format option if not specified.
 * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|false Date the current post was written. False on failure.
 */
function get_the_date($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $_format = (!empty($format)) ? $format : get_option('date_format');
    $the_date = get_post_time($_format, false, $post, true);
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $format   PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $format, $post);
}

WordPress Version: 5.5

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param string      $format Optional. PHP date format defaults to the date_format option if not specified.
 * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|false Date the current post was written. False on failure.
 */
function get_the_date($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' === $format) {
        $the_date = get_post_time(get_option('date_format'), false, $post, true);
    } else {
        $the_date = get_post_time($format, false, $post, true);
    }
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $format   PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $format, $post);
}

WordPress Version: 5.4

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param  string      $format Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post   Optional. Post ID or WP_Post object. Default current post.
 * @return string|false Date the current post was written. False on failure.
 */
function get_the_date($format = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $format) {
        $the_date = get_post_time(get_option('date_format'), false, $post, true);
    } else {
        $the_date = get_post_time($format, false, $post, true);
    }
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $format   PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $format, $post);
}

WordPress Version: 5.1

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
 * @return false|string Date the current post was written. False on failure.
 */
function get_the_date($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_date = get_post_time(get_option('date_format'), false, $post, true);
    } else {
        $the_date = get_post_time($d, false, $post, true);
    }
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $d        PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $d, $post);
}

WordPress Version: 4.6

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with the {@see 'get_the_date'} filter.
 *
 * @since 3.0.0
 *
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
 * @return false|string Date the current post was written. False on failure.
 */
function get_the_date($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_date = mysql2date(get_option('date_format'), $post->post_date);
    } else {
        $the_date = mysql2date($d, $post->post_date);
    }
    /**
     * Filters the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $d        PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $d, $post);
}

WordPress Version: 4.1

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with 'get_the_date' filter.
 *
 * @since 3.0.0
 *
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
 * @return false|string Date the current post was written. False on failure.
 */
function get_the_date($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_date = mysql2date(get_option('date_format'), $post->post_date);
    } else {
        $the_date = mysql2date($d, $post->post_date);
    }
    /**
     * Filter the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $d        PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $d, $post);
}

WordPress Version: 4.0

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with 'get_the_date' filter.
 *
 * @since 3.0.0
 *
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
 * @return string|bool Date the current post was written. False on failure.
 */
function get_the_date($d = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    if ('' == $d) {
        $the_date = mysql2date(get_option('date_format'), $post->post_date);
    } else {
        $the_date = mysql2date($d, $post->post_date);
    }
    /**
     * Filter the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $d        PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $d, $post);
}

WordPress Version: 3.9

/**
 * Retrieve the date on which the post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with 'get_the_date' filter.
 *
 * @since 3.0.0
 *
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
 * @return string Date the current post was written.
 */
function get_the_date($d = '', $post = null)
{
    $post = get_post($post);
    if ('' == $d) {
        $the_date = mysql2date(get_option('date_format'), $post->post_date);
    } else {
        $the_date = mysql2date($d, $post->post_date);
    }
    /**
     * Filter the date a post was published.
     *
     * @since 3.0.0
     *
     * @param string      $the_date The formatted date.
     * @param string      $d        PHP date format. Defaults to 'date_format' option
     *                              if not specified.
     * @param int|WP_Post $post     The post object or ID.
     */
    return apply_filters('get_the_date', $the_date, $d, $post);
}

WordPress Version: 3.7

/**
 * Retrieve the date the current $post was written.
 *
 * Unlike the_date() this function will always return the date.
 * Modify output with 'get_the_date' filter.
 *
 * @since 3.0.0
 *
 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
 * @return string|null Null if displaying, string if retrieving.
 */
function get_the_date($d = '')
{
    $post = get_post();
    $the_date = '';
    if ('' == $d) {
        $the_date .= mysql2date(get_option('date_format'), $post->post_date);
    } else {
        $the_date .= mysql2date($d, $post->post_date);
    }
    return apply_filters('get_the_date', $the_date, $d);
}