Today I just wanted to talk through a really simple WordPress function that you’ve all probably used – the_date() in your web design. So it’s pretty obvious what this function does just by reading the name, but if you haven’t gotten it by now, it simply returns the date a certain post/page was published.
The common usage for this function is in your loop. As I mentioned above, this could either be for aggregating a series of posts on a page, or even looping through custom post types.
The function
The function looks like the below and can be used with a number of parameters. These can be used to output the date in a format of your choice (available in the functions capabilities).
<?php the_date( $format, $before, $after, $echo ); ?>
So before I start going through the ins and outs of this function, there’s a instance where you shouldn’t use it, which seems to be most cases of needing to use it.
If you’re aggregating posts which have all been posted on the same date then the function works just fine. However, if you’ve got posts form a range of dates, the_date() function will only return the date from the first posted article.
The work-around
There’s two handy little functions you can use instead of the_date(). These are:
the_time() has to be used within the loop and has a parameter to spit out the time in the format you would like.
get_the_date() is also used within the loop and can be formated the same way as above.
Both functions as I’ve mentioned have date and time format capabilities, both of which can be found at the previous link.
I hope this has been of some use and will help anybody out that comes across this problem!



