Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

2 Answers

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);
    else
        $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);
    else
        $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.

share|improve this answer
    
+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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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