The date shortcode will return a formatted date. You can specify the date using an English string that is in the same format as PHP's strtotime
function.
For example,
{date:now}
will display the current date.
The format of the outputted date can be specified by passing a format
as a keyarg.
{date:now@format='Y-m-d'}
Formats
All supported formats are those of the date
function, which we summarise here and can also be found on the official PHP website.
| Description | Example returned values |
Day |
|
|
| Day of the month, 2 digits with leading zeros |
|
| A textual representation of a day, three letters |
|
| Day of the month without leading zeros |
|
| A full textual representation of the day of the week |
|
| ISO 8601 numeric representation of the day of the week |
|
| English ordinal suffix for the day of the month, 2 characters |
|
| Numeric representation of the day of the week |
|
| The day of the year (starting from 0) |
|
Week |
|
|
| ISO 8601 week number of year, weeks starting on Monday | Example: |
Month |
|
|
| A full textual representation of a month, such as January or March |
|
| Numeric representation of a month, with leading zeros |
|
| A short textual representation of a month, three letters |
|
| Numeric representation of a month, without leading zeros |
|
| Number of days in the given month |
|
Year |
|
|
| Whether it's a leap year |
|
| ISO 8601 week-numbering year. This has the same value as | Examples: |
| An expanded full numeric representation of a year, at least 4 digits, with | Examples: |
| An expanded full numeric representation if required, or a standard full numeral representation if possible (like | Examples: |
| A full numeric representation of a year, at least 4 digits, with | Examples: |
| A two digit representation of a year | Examples: |
Time |
|
|
| Lowercase Ante meridiem and Post meridiem |
|
| Uppercase Ante meridiem and Post meridiem |
|
| Swatch Internet time |
|
| 12-hour format of an hour without leading zeros |
|
| 24-hour format of an hour without leading zeros |
|
| 12-hour format of an hour with leading zeros |
|
| 24-hour format of an hour with leading zeros |
|
| Minutes with leading zeros |
|
| Seconds with leading zeros |
|
| Example: | |
| Milliseconds. Same note applies as for | Example: |
Timezone |
|
|
| Timezone identifier | Examples: |
| Whether or not the date is in daylight saving time |
|
| Difference to Greenwich time (GMT) without colon between hours and minutes | Example: |
| Difference to Greenwich time (GMT) with colon between hours and minutes | Example: |
| The same as | Examples: |
| Timezone abbreviation, if known; otherwise the GMT offset. | Examples: |
| Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. |
|
Full Date/Time |
|
|
| ISO 8601 date | 2004-02-12T15:19:21+00:00 |
| » RFC 2822/» RFC 5322 formatted date | Example: |
| Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | See also time() |
Adding and subtracting from a date
If you are getting the date dynamically for example from a meta field, you may need the date for the day before it, our a few hours later. You can do this simply by specifying it in the second argument to the shortcode:
The last day for registrations is {date:{acf:start_date} '-1 day'}
You can also specify more than one interval by separating them with a command:
{date:{acf:start_date} '-1 day, -1 hour'}
If you want more precision or use dynamic values, you can do it with the timedelta
shortcode, with the sub
and add
keyargs:
{date:{acf:start_date} @ sub={timedelta:@days=1 hours=2}}
The timedelta
accepted keyargs are: weeks, days, hours, minutes
and seconds
.
Date Comparisons
You can compare dates using the comparison shortcodes, for all dates that needs to be compared you should use a format that can be ordered, for example U
. Example.
{if: {gt: {date:{acf:start_date}@fmt=U} {date:now@fmt=U}}
[Registration opens on {acf:start_date}]
}
On any day before ACF start_date
the message in the second line will be displayed.