ThemeLib logo
  • Home
  • Blogger
    • Blogger Templates
    • Blogger Tutorials
    • Blogger Widgets
  • Wordpress
    • Wordpress Themes
    • Wordpress Plugins
    • Wordpress Tutorials
  • Money Makers
  • About
  • Contact
  • Advertise
Home » Wordpress Tutorials

The Ultimate Guide to WordPress Date and Time

This entry was posted by nhc on Sunday, September 14th, 2008 at 2:51 pm. It is filed under Wordpress Tutorials and tagged with date and time, tutorial, wordpress.

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 :D ). 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 :oops:

  • E-mail this story to a friend!
  • Print this article!
  • Digg
  • StumbleUpon
  • del.icio.us
  • Yahoo! Buzz
  • Technorati
  • Mixx

You've read the post. What's next?

If you like this post then please consider subscribing to our RSS feed. You can also subscribe by email to receive free updates directly in your inbox.

Want to know what am I doing? Follow me on Twitter!

Did you miss any of these related posts?

  • WordPress 2.7 Release Candidate 1
  • Wordpress 2.7 Project Icons - Vote Now!
  • WordPress 2.7 Beta 1 Is Out
  • Wordpress 2.6.5 Is Released
  • WordPress 2.6.3 Available for Download

6 Responses to "The Ultimate Guide to WordPress Date and Time"

  1. artikel pendidikan indonesia says:

    nice tutorial. thanks

    Reply to this comment »
    September 14, 2008 at 10:23 PM
  2. artikel pendidikan indonesia says:

    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

    Reply to this comment »
    September 16, 2008 at 4:25 AM
  3. Nihar says:

    Nice post showing all the options. i can now play around with the date formats and modify my index.php file.

    Thanks,
    Nihar

    Reply to this comment »
    September 25, 2008 at 8:53 AM
  4. Samantha says: Subscribed to comments

    I use very little the date and time features of WP - usually keeping the default settings-but this tutorial is complete
    cheers

    Reply to this comment »
    October 5, 2008 at 10:59 AM
  5. Arun Basil Lal says: Subscribed to comments

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

    Reply to this comment »
    December 15, 2008 at 3:07 PM
    • nhc says:

      When posting code, remember to convert all < character to “& l t ;” (without spaces) ;)

      Reply to this comment »
      December 15, 2008 at 6:02 PM

Leave a comment

Click here to cancel reply.

RSS feed

Feedburner RSS feed
Most articles on this site are related to blogger templates, wordpress themes, blog design, tips, tricks, and plenty of fun :)

Grab the feed or enter your email address to get the party started! It is FREE.

Search our archives

Categories

  • Blogger Hacks
  • Blogger Templates
  • Blogger Tutorials
  • Blogger Widgets
  • Blogging Tips
  • Favourite Links
  • Google News
  • Make Money Online
  • Personal
  • Reviews
  • Site News
  • Web Stuff
  • Wordpress News
  • Wordpress Plugins
  • Wordpress Themes
  • Wordpress Tutorials

Archives

  • January 2009 (2)
  • December 2008 (17)
  • November 2008 (15)
  • October 2008 (15)
  • September 2008 (11)
  • August 2008 (26)
  • July 2008 (27)
  • June 2008 (16)

Entrecard Blog

Featured Links

  • Joomla Templates
  • Domain Name Registration
  • Slightly mordant
  • Your links here, $10/month

Top Commentators

  • Alex (3)
  • Typhoon (3)
  • brooks (2)
  • Jacques Seoman (2)
  • Make Money (2)

Recent Posts

  • Revolution Themes Became Paid Themes with GPL License!
  • eGamer Wordpress Theme for Video Game Bloggers
  • Google Pagerank Update December 2008 - ThemeLib is now PR6!
  • Viewport Wordpress Theme from Smashing Magazine
  • 50+ “your ad here” 125×125 banners
  • Merry Christmas Everybody!
  • Simple Text Premium Wordpress Theme
  • Wordpress Theme Reviews and Ratings at ThemesPreview
  • How to Find Spam Blogs Republish Your RSS Feeds and Make Good Use Of It
  • Woo Themes Christmas Special - Buy One and Get Three Free!

Popular Posts

  • Arthemia magazine blogger template (290)
  • Google PageRank update September 2008 - My blog got PR5 (108)
  • Maggo magazine blogger template (80)
  • Personal Mag magazine blogger template (66)
  • Astro colorful blogger template (62)
  • White Space blogger template (60)
  • Google Pagerank Update December 2008 - ThemeLib is now PR6! (57)
  • SunRays dark blogger template (40)
  • Windows Vista blogger template (39)
  • Rebel magazine blogger template (38)
  • Revolution Themes Now Available to Download - FREE (37)
  • Link love to Top Commentators :) (36)

Recent Comments

  • Typhoon:nhc posted this news almost a month back.I think you should subscribe to his fe
  • brooks:I am so proud that Google is giving such high PR's to websites
  • brooks:Being a gaming buff, I am so happy that wordpress has come up with this amazing
  • nhc:Search for the code below and change it. body { font-family: Century gothi
  • nhc:You can link to your favorite posts, blog's labels or something you like. It do
  • nhc:I'm sure you did something wrong with the template
  • nhc:Thanks. I'm dreaming of a PR7 too :
  • Yoginder:Thats a very good achievement. All the best and get a P7 or more :
Copyright
Links
© 2008 - 2009 ThemeLib. Some Rights Reserved. Arthemia Theme by MichaelJubel - Enhanced by ThemeLib
About Us | Contact Us | Advertise With Us | Hire Us | Terms of Service | Privacy Policies | RSS Feed | Email Subscription | Sitemap | Log In