How To Format Date Time In WordPress

Formatting Date and Time in WordPress


Overview Patterns Examples



Overview

In WordPress, displaying the date and time is often done via using the the_date() and the_time() functions in your PHP code.  These functions accept a format string parameter that allows you to determine how the date is going to be displayed. To change how the date and time is displayed, open the General Settings page via the Settings => General menu in your WordPress dashboard and locate the date time format options. In this area, you can manipulate the date and time to display as you wish.

More documentation for formatting the date and time in worpress can be found below.

https://codex.wordpress.org/Formatting_Date_and_Time

Patterns

Day of Month
d Numeric, with leading zeros 01–31
j Numeric, without leading zeros 1–31
S The English suffix for the day of the month st, nd or th in the 1st, 2nd or 15th.
Weekday
l Full name  (lowercase ‘L’) Sunday – Saturday
D Three letter name Mon – Sun
Month
m Numeric, with leading zeros 01–12
n Numeric, without leading zeros 1–12
F Textual full January – December
M Textual three letters Jan – Dec
Year
Y Numeric, 4 digits Eg., 1999, 2003
y Numeric, 2 digits Eg., 99, 03
Time
a Lowercase am, pm
A Uppercase AM, PM
g Hour, 12-hour, without leading zeros 1–12
h Hour, 12-hour, with leading zeros 01–12
G Hour, 24-hour, without leading zeros 0-23
H Hour, 24-hour, with leading zeros 00-23
i Minutes, with leading zeros 00-59
s Seconds, with leading zeros 00-59
T Timezone abbreviation Eg., EST, MDT …
Full Date/Time
c ISO 8601 2004-02-12T15:19:21+00:00
r RFC 2822 Thu, 21 Dec 2000 16:01:07 +0200
U Unix timestamp (seconds since Unix Epoch) 1455880176

 

Date and Time Formatting WordPress Examples

  • F j, Y g:i a – January 1, 2018 11:36 am
  • F j, Y – January 1, 2018
  • F, Y – January , 2018
  • g:i a – 11:36 am
  • g:i:s a – 11:36:13 am
  • l, F jS, Y – Friday, January 1st, 2018
  • M j, Y @ G:i – Jan 1, 2010 @ 11:36
  • Y/m/d \a\t g:i A – 2018/1/01 at 11:36 AM
  • Y/m/d \a\t g:ia – 2018/1/01 at 11:36am
  • Y/m/d g:i:s A – 2018/1/01 11:36:13 AM
  • Y/m/d – 2018/1/18