{date_created} Merge Tag
The {date_created}
Merge Tag allows you to display the date an entry was created.
By default, the {date_created}
Merge Tag will format the entry using the WordPress "Date Format" setting from the General Options screen.
Example usage:
{date_created}
will output February 21, 2016
Add the time to the output
:time
Adds "at [time]
" to the output, where[time]
is formatted using the Time Format setting from the General Options screen.
Format the output using PHP date format
The :format Merge Tag modifier can only be used with the {date_created} Merge Tag. If you want a modifier for other Date fields, please try this plugin instead.
Gravity Forms supports using merge tag modifiers on any date field: https://docs.gravityforms.com/date/#h-modifiers
Use :format
to define a custom format for the date output. The format must be defined after :format
, then a colon, like this :format:m/d/Y
.
If you want to use a colon in your output, you must escape the colon with a backslash, like this \:
.
Examples:
{date_created}
will outputFebruary 21, 2016
{date_created:time}
will outputFebruary 21, 2016 at 3:09 pm
{date_created:format:m/d/Y}
will output02/21/2016
{date_created:format:m/d/Y\ \a\t\ H\:i\:s}
will output02/21/2016 at 15:09:12
- note the additional escape character\
before the colons.
{date_created:human}
Let Gravity Forms decide how to output the date for you.
If the entry is less than a day old, it will output a relative date using the [time] ago
format. This cannot be overridden. If you want to customize the format, use the :diff
modifier and define a custom :format
instead. See ":diff Modifier" below.
If the entry is more than a day old, it will output the date using the blog's Date Format setting. If the :time
modifier is also defined, it will output "[date] at [time]" using the website's Date Format and Time Format settings.
Examples:
{date_created:human}
- Older than 24 hours:
February 21, 2016
. Format based on blog Date Format setting. If the entry is less than 24 hours old:
14 hours ago
Outputs using Human Time Difference format, but when using
:human
, the output template cannot be changed from%s ago
like it can with:diff
.
- Older than 24 hours:
{date_created:human:time}
- If the entry is less than 24 hours old:
14 hours ago
- Older than 24 hours will output using blog date and time format:
February 21, 2016 at 3:09 pm
- If the entry is less than 24 hours old:
{date_created:diff}
Show how long ago an entry was created, not the date itself
:diff
outputs the time difference from the entry creation date.
{date_created:diff}
will output different values based on how long ago the entry was created. The standard format is %s ago
, where %s
is replaced by the time difference.
3 minutes ago
14 hours ago
28 days ago
2 years ago
When using :diff
, :time
and :human
modifiers will not work.
Override the format
You can use the :format
parameter to change the output template. If we want to output "I submitted the form [time difference] in the past", we would use this Merge Tag: {date_created:diff:format:I submitted the form %s in the past}
:
I submitted the form 3 minutes in the past
I submitted the form 14 hours in the past
I submitted the form 28 days in the past
I submitted the form 2 years in the past
Make sure to keep the %s
intact; the %s
represents where the time difference will be inserted.
Additional stand-alone modifiers
You cannot combine these modifiers with other modifiers. If they exist in the Merge Tag, they will be used in the order defined, and the other modifiers will be ignored.
:raw
Return the date_created value, as stored by Gravity Forms in the database (inYYYY-MM-DD HH:MM:SS
format).- Example:
{date_created:raw}
outputs2016-02-21 15:09:24
- Example:
:timestamp
Return a Unix Timestamp of the entry creation. This is useful when comparing date values usinggreater_than
andless_than
in combination with the [gvlogic] shortcode.- Example:
{date_created:timestamp}
generates1456067364
(see here)
- Example: