Using the Date
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. The format used must match the format used in the PHP's date function, for example {date:now@format='Y-m-d'}
.
For a full list of supported formats refer to the PHP date reference page.
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'}
Adding and subtracting from a date (advanced)
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.