What’s the difference between get_the_time and get_the_date?

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

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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:

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