How to Use PHP Date and Time Formats in WPForms

Would you like to customize how dates and times are displayed in your WPForms? By using PHP date and time parameters, you can format dates and times in various ways to best suit your forms and your users’ needs.

In this guide, we’ll walk you through the most common PHP date and time format characters.

Understanding Date Format Characters

Here’s a table of the most commonly used characters for formatting dates in WPForms:

Format CharacterDescriptionexample output
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase ‘L’)A full textual representation of the day of the weekSunday through Saturday
NISO 8601 numeric representation of the day of the week1 (for Monday) through 7 (for Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersstndrd or th. Works well with j
wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
zThe day of the year (starting from 0)0 through 365
WISO 8601 week number of year, weeks starting on MondayExample: 34 (the 34th week in the year)
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
tNumber of days in the given month28 through 31
LWhether it’s a leap year1 if it is a leap year, 0 otherwise.
oISO 8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.Examples: 1997 or 2009
YA full numeric representation of a year, at least 4 digits, with – for years BCE.Examples: -0044, 0657, 1997, 2006, 20191
yA two digit representation of a yearExamples: 97 or 06
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59
uMicrosecondsExample: 654321
vMillisecondsExample: 654
eTimezone identifierExamples: UTC, GMT, America/New_York
I (capital i)Whether or not the date is in daylight saving time1 if Daylight Saving Time, 0 otherwise.
ODifference to Greenwich time (GMT) without colon between hours and minutesExample: +0200
PDifference to Greenwich time (GMT) with colon between hours and minutesExample: +02:00
TTimezone abbreviationExamples: EST, EDT
ZTimezone offset in seconds-43200 through 50400
cISO 8601 date2023-09-09T15:45:30-04:00
rRFC 2822 formatted dateWed, 09 Sep 2023 15:45:30 -0400

Using Date Formatting in WPForms

To use these format characters in WPForms, you’ll typically combine them into a string. Here are some common examples:

  1. Y-m-d: 2024-10-21 (Year-Month-Day)
  2. d/m/Y: 21/10/2024 (Day/Month/Year)
  3. F j, Y: October 21, 2024 (Month Day, Year)
  4. D, d M Y: Mon, 21 Oct 2024 (Abbreviated Day, Day Month Year)

Practical Examples in WPForms

Here are some ways you might use custom date formatting in WPForms:

  1. In Smart Tags: Use the {date} smart tag with custom formatting:
    • {date format="Y-m-d"} would output the current date as 2024-10-21
    • {date format="F j, Y"} would output October 21, 2024
  2. In Date/Time fields: When setting up a Date/Time field, you can customize the date format:
    • Using d/m/Y for a day/month/year format
    • Use M j, Y for a shortened month name format like Oct 21, 2024

Note: The default Date/Time field in WPForms offers limited format options. To use custom formats like those mentioned above, you’ll need to create additional formats using a PHP snippet. Please refer to our guide on creating additional date/time formats for more details.