How To Customize The Time And Date In WordPress?

In WordPress you sometimes need to show dates and time. For example, when you want to show date or time below a WordPress post showing when that post was posted or the article publishing date and time. You also need to show date in your blog copyright notice. You may also want to show dates and time in Recent post tabular form or most viewed posts, etc. You may have to show dates and time in many palces else where. So how to do that?

To show dates and time, you will have to use some PHP functions. They will show date,time in any form you desire. You may customize the form in which the dates or time are displayed. Certain WordPres tag functions are used to display date and time information. “the_date()” and “the_time()” are a few examples of this.

Some of these functions accept a parameter called a format string that allows you to determine how the date or time is going to be displayed. The format string is a template in which various parts of the date are combined using format characters to generate a date in the specified format according to your wish.

Some format strings:

  1. l, F j, Y –> Monday, February 8, 2010
  2. F j, Y –> February 8, 2010

There are almost innumerable combinations and styles you can create.

Here is what each format character in the string above represents:

  • l = Full name for day of the week.
  • F = Full name for the month.
  • j = The day of the month.
  • Y = The year in 4 digits (Using lower-case “y” gives the year’s last 2 digits like 09 or 10,etc.)

If you use commas in the code, they will be read as simple text. They won’t have any affect on the code. A “,” will display “,”.

As WordPress is written in the programming language PHP, the date formatting functions in WordPress use PHP’s built-in date formatting functions. You can use the date format characters specified on the PHP website for displaying dates and times in WordPress. All of them there will work in WordPress.

The code,

<?php the_time('l, F j, Y') ?>

will display Monday, February 8, 2010.

You can customize l, F j, Y according to your wish and look you want.

That’s it for today! Stick to Blogging Junction for new posts!

Leave a Comment

{ 8 comments… read them below or add one }

Basant Singh February 9, 2010 at 3:26 PM

Helpful post for WP bloggers

Reply

Saksham Talwar February 9, 2010 at 8:07 PM

Thanks Basant! Great that you found the post helpful!

Reply

Pubudu Kodikara February 9, 2010 at 9:25 PM

Time is very important! time is equal to gold! :D

Reply

Saksham Talwar February 10, 2010 at 12:07 AM

Time is gold in my opinion! BTW you are not wrong.

Reply

Babaji M P February 10, 2010 at 6:03 AM

@ Pubudu Kodikara, Saksham Talwar …

Golden words at the right time :) :) :)

Reply

Saksham Talwar February 10, 2010 at 6:05 AM

Thanks!

Reply

abhi February 10, 2010 at 10:55 AM

Thanks for the tip. They use PHP based date function. I prefer the default format.

Reply

Saksham Talwar February 10, 2010 at 8:49 PM

You’re welcome! Yeah they use PHP based date function like used in other PHP applications.

Reply