How to format the date and time in WordPress

In WordPress, the date and time are retrieved and displayed using template tags, such as the_date and the_time. Some template tags can be used with format parameters to specify how the output is displayed. For example,  the_time with the parameters shown below:

<?php the_time('l, F jS, Y') ?>
is displayed in a published post or page as:

Monday, September 25th, 2017

Note that format parameters are case-sensitive, and commas (,) and slashes (/) are displayed exactly as written in the format string between the parentheses.

Format parameters

Log in to WordPress via the HostPapa Dashboard. Because it is written in the PHP programming language, WordPress date formatting uses PHP date formatting functions. Some of the most commonly used parameters are described below.

Parameter Displayed result Example
Month
F The full name of the month January – December
M The three-letter abbreviation of the month Jan – Dec
m The numeric month with leading zeros 01 – 12
n The numeric month without leading zeros 1 – 12
Day of the month
d The numeric day of the month with leading zeros 01 – 31
 j The numeric day of the month without leading zeros 1 – 31
S The suffix for the numeric day of the month st (in 1st), nd (in 2nd)
Weekday
l (lower-case L) The full day of the week Monday – Sunday
D The three-letter abbreviation of the day of the week Mon – Sun
Year
Y The four-digit year 2017
y The two-digit year 17
Time
a Lower-case am or pm am, pm
A Upper-case AM or PM AM, PM
g The hour in 12-hour format without leading zeros 1 – 12
h The hour in 12-hour format with leading zeros 01 – 12
G The hour in 24-hour format without leading zeros 0 – 23
H The hour in 24-hour format with leading zeros 00 – 23
 i Minutes with leading zeros 00 – 59
s Seconds with leading zeros 00 – 59
T The abbreviated time zone PST, EDT
Full date and time  
c ISO 8601 2017-09-12T15:19:21+00:00
r RFC 2822 Mon, 25 Sep 2017 16:01:07 +0200
U Unix timestamp (seconds since Unix Epoch) 1455880176

Template tag examples

The table below includes examples of how formatted parameters are used with the the_time template tag and displayed in published WordPress posts. In the last example (Monday, September 25th, 2017 at 1:01 PM), note that the ‘a’ and ‘t’ characters in the format parameter string require preceding backslashes (\) to be displayed as the word ‘at’ in the published post.

Template tag with format parameters Displayed date or time
<?php the_time('Y/m/d') ?> 2017/09/25
<?php the_time('Y/n/d') ?> 2017/9/25
<?php the_time('F j, Y') ?> September 25, 2017
<?php the_time('M j, Y') ?> Sep 25, 2017
<?php the_time('h:i A') ?> 01:01 PM
<?php the_time('H:i a') ?> 13:01 pm
<?php the_time('l, F jS, Y \a\t g:i A') ?> Monday, September 25th, 2017 at 1:01 PM

More information

For more information about template tags and customizing how dates and times are displayed, check out these resources:

If you need help with your HostPapa account, please open a support ticket from your dashboard.

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache