Both function returns date and time. What's the difference between them? Do you have any example? Thanks.

  • The real question for me is why is the template tag called "the_time()" but the "get" version is "get_the_date()"!?
    – Tom Auger
    Aug 30 '11 at 19:18

They are, very similar but with some nuances:

function get_the_date( $d = '' ) {
    global $post;
    $the_date = '';

    if ( '' == $d )
        $the_date .= mysql2date(get_option('date_format'), $post->post_date);
        $the_date .= mysql2date($d, $post->post_date);

    return apply_filters('get_the_date', $the_date, $d);

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);
        $the_time = get_post_time($d, false, $post, true);
    return apply_filters('get_the_time', $the_time, $d, $post);
  1. get_the_date() always works for current global $post, get_the_time() allows you to specify post as argument.

  2. They default to different formats, stored in date_format and time_format options respectively.

  3. They pass output through different filters get_the_date and get_the_time plus lower level get_post_time respectively.

  • +1 for quoting source code. Why guess what's going on under the hood when you can take a look.
    – Michal Mau
    Aug 29 '11 at 12:06

The the_date() template tag only outputs the post date once per occurrence; thus, if two or more posts have the same post date, that date is only output at its first occurrence in the Loop. The the_time() template tag outputs the post time (using any valid date/time string), as per normal.

The get_the_date() and get_the_time() template tags, however, are essentially the same. They are used to return the respective value for the_date() and the_time(). As per the Codex:

Unlike the_date() this tag will always return the date. Modify output with 'get_the_date' filter.

So, the difference lies not in the get_the_*() template tags themselves, but in the the_*() template tags that use them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.