Wordpress Date and Time – How Do You Format Them?
The use of dates and times are key in Wordpress blogs for giving your readers a sense of when the content on your site was posted and how recent (or old) it is. However, if you attempt to change the appearance of the dates and times displayed on your blog (e.g. in your post metadata or footer sections) it can be a little daunting and confusing at first.
The characters used for formatting the date are not that intuitive and it can be unclear what exactly you need to do to get the look you’re after.
The main format characters used are the following: l, F, j, and S. Any idea what they refer to? It’s difficult to tell without referring to the documentation – an overview is provided below:
l = The name of the day (e.g. Monday)
F = The name of the month (e.g. January)
j = The day of the month (e.g. 25)
S = The English suffix that goes at the end of a number (e.g. 1st, 2nd, 3rd, 4th)
This becomes clearer if we look at some examples:
the_time(‘l F j, Y’) = Thursday September 17, 2009
the_time(‘l jS F Y’) = Thursday 17th September 2009
the_time(‘Y’) = 2009
the_time(‘jS F Y’) = 17th September 2009
Note that the use of commas is explicit – that is, wherever you place a comma that is where it will be displayed. For example, if you used the following format … (you probably wouldn’t, but I’m using it just to make the point clear):
<?php the_time('l, jS, F, Y') ?>
… you’d get the following output:
Thursday, 17th, September, 2009
Another useful template tag is “the_modified_date” – this displays the date that a blog post was last modified and is particularly helpful if you have a page or post that you update regularly and need to inform your readers that it has been updated.
All you need to do to display the last modified date is the following:
<?php the_modified_date(); ?>
It’s important to note, however, that use of this tag will only work outside of the Wordpres loop – if you try to use it inside you’ll likely get some problems.
The other place that you are likely to want to format the Wordpress Date and Time is in your footer and all too often website owners manually code this as opposed to making use of the functions that Wordpress provides.
This can be done very simply using something like the following:
Copyright © <?php the_time('Y') ?> <?php bloginfo('name'); ?>
This will produce the following output: Copyright © 2009 Voosh Themes
The nice thing about this approach is that you only have to code it once and you’re done – it will automatically update when the new year arrives. This is in contrast to manually hard coding where you’ll have to ensure that you update it year on year (and probably end up forgetting!)
Hopefully this helps clear things up about Wordpress Date and Time – it’s not that intuitive to use at first, but once you get the hang of it and understand what the different variables refer to, it’s generally simple and straightforward to use.















