The Ultimate Guide to WordPress Date and Time
In this tutorial, I’ll be going over The Date and The Time, and how can you use it to display your posts information. Hopefully you will find this ultimate guide easier to understand and follow than what’s available in the WordPress documentation.
The Date and Time format string
- l = Full name for day of the week (lower-case L).
- F = Full name for the month.
- j = The day of the month.
- S = The English suffix for the day of the month (e.g st, nd or th in the 1st, 2nd or 15th.)
- Y = The year in 4 digits. (lower-case y gives the year’s last 2 digits)
Here are examples of the various formats for date and time:
- l, F j, Y – Friday, March 5, 2009
- m/j/y g:i A – 05/12/09 7:30 AM
- j F Y – 25 May 2009
- Y – 2009
Adding the Date and the Time to your posts
You can display your post information in the post meta data section in the form of a sentence:
This entry was posted on <?php the_time('l, F jS, Y') ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(', ') ?>
The result should be something like this :
This entry was posted on 15 August 2008 at 12:41 am and is filed under WordPress Tutorials.
Note: Even though we can use the_date() tag to display your post date, it is highly not recommended because when there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()).
Display the Date and the Time your post was modified
The the_modified_date template tag displays the date your post was last modified, and the_modified_time() displays the last modified time. Note that these only work when used within the WordPress Loop, the code that generates your post content information.
Code :
This post was published on <?php the_date('F j, Y'); ?> and was last modified on <?php the_modified_date(); ?> at <?php the_modified_time() ?>
Result :
This post was published on July 4, 2008 and was last modified on December 13, 2009 at 7:30 am
This is helpful for helping update your readers so they know when your blog post was last updated. You can find more variations on using the date and time in the the_date and the_time() WordPress Template Tags, but let’s take this a little further.
Copyright Date
As you know, most copyright statements don’t need the full date, we only need the year. Many bloggers hard-code the year in their copyright statement (me too
). In my opinion, it is fine because it is not required us update regularly, just one per year. In fact we could use the PHP date commands to recreate a constantly updating year on the copyright statement.
Using the PHP date commands, you can set your copyright statement to automatically update every year
In your footer.php template file add the following code :
Copyright © <?php the_time('Y'); ?> <?php bloginfo('name'); ?>
This will display:
Copyright © 2009 ThemeLib
Conclusion
So now you (hopefully) have a better insight on the WordPress Date and Time. Feel free to leave a comment if you liked it, hated it, couldn’t understand, whatever – I welcome all feedback. Do not forget to subscribe to my feed for all the latest updates on ThemeLib theme releases and new tutorials. Thanks for reading.
P/s: I “stole” the article title of the post The Ultimate Guide to the WordPress Loop on ThemeLab

















Twitter

nice tutorial. thanks
hey, i saw a very simple but cool template today. it is VERYPLAINTXT wordpress template by SCOTT WALLICK. You can see the demo here
would you please convert it to blogger? i’ll wait
Nice post showing all the options. i can now play around with the date formats and modify my index.php file.
Thanks,
Nihar
I use very little the date and time features of WP – usually keeping the default settings-but this tutorial is complete
cheers
Hey,
i have a question,
Using the code for the example “This post was published on July 4, 2008 and was last modified on December 13, 2009 at 7:30 am” will display was modified on even if the post was not modified..rgiht..?
I mean, was modified on will be there even if the modified date returns null of the same date.
I think the following code can fix thies:
Posted on <?php $u_modified_time = get_the_modified_time('U');if ($u_modified_time != $u_time) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo ". "; } ?>
Thanks. Cheers..
When posting code, remember to convert all < character to “& l t ;” (without spaces)
I have never heard about Copyright date. Thanks for sharing this info.
I like what you have posted, but a better tutorial could be found at wordpress.org
How do I add the current date and time to the header?
Very nice tutorial. I appreciate your work and time in laying this out for us.
hey, this is very handy and useful tutorial, I have tried few techniques given in this tutorial and all are working fine for me.
thanks for sharing
Is it possible to make it ‘shot-form’ instead of full name of the month?