No matter you want to abbreviate the month, hide the year, or make any other changes to your date and time styling, you can achieve it in a painless manner with our detailed guidance in the sections below.
Understand and Modify Date and Time Format in WordPress
In the very beginning, you need to visit “Settings” > “General” on your dashboard. Then, scroll down the page and you will see a “Timezone” section. As the screenshot below shows, you are granted with a number of built-in options to modify WordPress date and time format.
You can get started by selecting a timezone, date format, and time format with the options available here. Alternatively, you can create a custom format using a preferred format string.
Generally speaking, a format string is a template that combines various parts of the date or time using some format characters like l, F, j, Y, and i. These format characters represent the full name for day of the week, full name for the month, the day of the month, the year in 4 digits, and the minutes with leading zeros respectively.
In regular, different format string will output different date and time styling. Here are some frequently-seen format stings and their result outputs. If you want to learn more about this point, please visit this page.
- F j, Y – April 6, 2016
- F j, Y g:i a – April 6, 2016 9:27 am
- l, F jS, Y – Wednesday, April 6th, 2016
- F j, Y g:i a – April 6, 2016 9:28 am
- Y/m/d \a\t g:i A – 2016/04/06 at 9:29 AM
- Y/m/d g:i:s A – 2016/04/06 9:29:47 AM
From the illustrations above, it is clear that you can keep defining how the date and time will be displayed on your website to achieve the result that best suits your needs in the real world. Here, you are almost done with all the settings and WordPress will use the format you have just created throughout your website after clicking the “Save Changes” button.
As a side note, we will provide some more targeted suggestions to help you create custom date and time formats in different situations as below.
Situation 1 – Display Time Next to Dates
It is widely-known that WordPress displays only the publish date of a post by default. However, in some cases you may prefer to show the date along with time. To be frank, this is fairly simple to accomplish.
All you need here is a format string that contains both date-related characters and time-related characters. For example, you can add the format string Y/m/d \a\t g:i A to the “Date Format” or “Time Format” section on the “General Settings” page and save changes. Then, the system will display both the publish date and time of a post as below.
Situation 2 – Display the Last Updated Date
For most authors as well as site admins, it is common to make updates to a published posts. In this case, you can choose to display the last updated date of the post to inform your readers that the post has been modified.
To do this, you need to locate the code below in index.php, single.php, and page.php of your WordPress theme files.
In the next, replace it with the following code. When you are done with these operations, you can now visit a post and see it displayed with the last updated date.
Situation 3 – Display Current Date
Over the web, more and more bloggers are displaying their posts with current dates, which can be a bonus item that makes their websites look professional. If you want to show up your posts in the same way, then the following operations are designed right for you.
Simply copy and paste the following code to a theme file of your WordPress site on the basis of your preference. And then the system will output a format like Wednesday, April 6th, 2016. If for any reasons you do not like this format, you can change the parameters at your convenience.
Situation 4 – Display Relative Dates
Displaying relative dates, one of the most popular concepts adopted by many social media sites, are now widely accepted by WordPress bloggers to organize their posts as well as comments. For example, you can tell your readers that a certain post was published two days ago or a comment was submitted 15 minutes ago.
Similarly, you do not need to consume much energy and time to accomplish the task above.Firstly, find the code in one of the three theme files – single.php, page.php, and comments.php.
Then, replace it with the following one and you are done.
On the Bottom
To sum up, you can use the built-in options coming with WordPress to modify your date and time format. Also, you can create various custom formats using different format strings.
It is true that the suggestions provided above involve a certain amount of coding skills, which might be a headache for some inexperienced users. However, they are indeed helpful for you to create an optimal time and date format without some nasty errors generated by leveraging a plugin.