When you start blogging, each of your WordPress posts gets automatically stamped with date time format once you hit the Publish button. This date, and sometimes the time too, is displayed in a variety of locations throughout your WordPress website.
Did you know that you're able to completely customize the format used for displaying this date time information using your WordPress admin dashboard, with no coding required? In this quick tutorial you'll learn how to change the PHP date format in WordPress.
As WordPress is written in the PHP programming language, you're able to make use of the PHP date function that allows you to display customized date time formats using format characters. First of all, open the General Settings page via the Settings => General admin menu in your WordPress dashboard and locate the date time format options, as shown below in the image. Here you can change the PHP date format for your WordPress website as you like.
WordPress offers you a variety of pre-defined formats that you can choose to use, as well as allowing you to add a custom format of your choice. Using the PHP date function, you can create your own date and time formats by adding format characters into the field alongside the Custom option. From this settings page, you're also able to choose your timezone, with the default setting being UTC+0.
The available format characters have been divided into sections to make things easier when it comes to finding the character you're looking for. Here is a selection of the most commonly used format characters. Please also refer to the documentation within the WordPress Codex as well as to the PHP Manual full documentation. There you'll find a preview of all available characters for the PHP date & time format.
h – The hour of the day using two digits, such as 01, 05, 11.
H – The hour of the day using two digits, in 24-hour format, such as 07, 13, 22.
g – The hour of the day using up to two digits, such as 3, 8, 12.
G – The hour of the day using up to two digits, in 24-hour format, such as 00, 15, 21.
A – Displays either Ante meridiem and Post meridiem using uppercase letters, such as AM or PM.
a – Displays either Ante meridiem and Post meridiem using lowercase letters, such as am or pm.
i – The minute of the hour using two digits, such as 05, 32, 59.
s – The second of the minute using two digits, such as 01, 48, 51.
e – The timezone identifier in full, such as Europe/Berlin, America/New York.
T – The timezone identifier abbreviated, such as EST, GMT, MDT.
O – Difference, in hours, to the GMT timezone, such as +0100, +0530, +0800.
P – Difference, in hours, to the GMT timezone, colon separated, such as +02:00, +04:00, +07:30.
d – Day of the month using two digits, such as 01, 18, 31.
j – Day of the month using up to two digits, such as 1, 8, 24.
S – Display ordinal indicators, such as st, nd, rd, or th.
D – Day of the month using three letters, such as Mon, Wed, Sun.
l – Day of the month in full, such as Monday, Thursday, Saturday.
m – Month of the year using two digits, such as 01, 07, 11.
n – Month of the year using up to two digits, such as 2, 9, 12.
M – Month of the year using three letters, such as Mar, Aug, Nov.
F – Month of the year in full, such as January, May, October.
y – The year using two digits, such as 97, 03, 14.
Y – The year in full, such as 1984, 2001, 2016.
You can also use other format characters within your date format code to customize your format, such as commas, brackets, slashes and hyphens, like so:
l, jS F, Y = Monday, 15th August, 2016 m/d/y = 08/15/16
This allows you to add separators amongst the date format to make the date clear and readable to your website visitors. You're also able to add text within your format code, simply prefix each letter with a backward slash (\). To add the word at in between your date and time formats, you could use:
m/d/y \a\t H:G = 08/15/16 at 16:02
Date & time formatting tools available
There are a handful of date time formatting tools available for you to use. These tools can help you create your desired format. DateFormat.io is a good example as it allows you to select dates and times using an easy to use interface, giving you the format code to recreate the format elsewhere.
Simply select PHP from the programming language selector and start clicking on your chosen date time formats. A live preview of your chosen format can be viewed at the bottom of the page where you will also find the format code that it has created for you. You can copy the code for use on your website as custom PHP date format.
Conclusion: Customizing date and time formats
Using the above listed format characters and generators, you can easily customize the date and time output throughout your entire WordPress website. That way you can always show your preferred formats for date and time. As you're making use of a built-in WordPress feature, the above date time format will also persist should you change your WordPress theme some time in the future. Have you ever tried to change the WordPress date format?