Both function returns date and time. What’s the difference between them? Do you have any example? Thanks.
Leave a Reply
You must be logged in to post a comment.
Both function returns date and time. What’s the difference between them? Do you have any example? Thanks.
You must be logged in to post a comment.
They are, very similar but with some nuances:
get_the_date()
always works for current global$post
,get_the_time()
allows you to specify post as argument.They default to different formats, stored in
date_format
andtime_format
options respectively.They pass output through different filters
get_the_date
andget_the_time
plus lower levelget_post_time
respectively.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. Thethe_time()
template tag outputs the post time (using any valid date/time string), as per normal.The
get_the_date()
andget_the_time()
template tags, however, are essentially the same. They are used to return the respective value forthe_date()
andthe_time()
. As per the Codex:So, the difference lies not in the
get_the_*()
template tags themselves, but in thethe_*()
template tags that use them.