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 Character | Description | example output |
---|---|---|
d | Day of the month, 2 digits with leading zeros | 01 to 31 |
D | A textual representation of a day, three letters | Mon through Sun |
j | Day of the month without leading zeros | 1 to 31 |
l (lowercase ‘L’) | A full textual representation of the day of the week | Sunday through Saturday |
N | ISO 8601 numeric representation of the day of the week | 1 (for Monday) through 7 (for Sunday) |
S | English ordinal suffix for the day of the month, 2 characters | st , nd , rd or th . Works well with j |
w | Numeric representation of the day of the week | 0 (for Sunday) through 6 (for Saturday) |
z | The day of the year (starting from 0) | 0 through 365 |
W | ISO 8601 week number of year, weeks starting on Monday | Example: 34 (the 34th week in the year) |
F | A full textual representation of a month, such as January or March | January through December |
m | Numeric representation of a month, with leading zeros | 01 through 12 |
M | A short textual representation of a month, three letters | Jan through Dec |
n | Numeric representation of a month, without leading zeros | 1 through 12 |
t | Number of days in the given month | 28 through 31 |
L | Whether it’s a leap year | 1 if it is a leap year, 0 otherwise. |
o | ISO 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 |
Y | A full numeric representation of a year, at least 4 digits, with – for years BCE. | Examples: -0044, 0657, 1997, 2006, 20191 |
y | A two digit representation of a year | Examples: 97 or 06 |
a | Lowercase Ante meridiem and Post meridiem | am or pm |
A | Uppercase Ante meridiem and Post meridiem | AM or PM |
g | 12-hour format of an hour without leading zeros | 1 through 12 |
G | 24-hour format of an hour without leading zeros | 0 through 23 |
h | 12-hour format of an hour with leading zeros | 01 through 12 |
H | 24-hour format of an hour with leading zeros | 00 through 23 |
i | Minutes with leading zeros | 00 to 59 |
s | Seconds with leading zeros | 00 through 59 |
u | Microseconds | Example: 654321 |
v | Milliseconds | Example: 654 |
e | Timezone identifier | Examples: UTC, GMT, America/New_York |
I (capital i) | Whether or not the date is in daylight saving time | 1 if Daylight Saving Time, 0 otherwise. |
O | Difference to Greenwich time (GMT) without colon between hours and minutes | Example: +0200 |
P | Difference to Greenwich time (GMT) with colon between hours and minutes | Example: +02:00 |
T | Timezone abbreviation | Examples: EST, EDT |
Z | Timezone offset in seconds | -43200 through 50400 |
c | ISO 8601 date | 2023-09-09T15:45:30-04:00 |
r | RFC 2822 formatted date | Wed, 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:
Y-m-d
: 2024-10-21 (Year-Month-Day)d/m/Y
: 21/10/2024 (Day/Month/Year)F j, Y
: October 21, 2024 (Month Day, Year)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:
- 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
- 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
- Using
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.