Current Time Merge Tags in Gravity Forms
Automatically populate the current time into a field, confirmations, and notifications.
Insert the Current Time into Fields
Gravity Forms has included built-in merge tags to populate the current date into a field for quite a while: {date_mdy}
and {date_dmy}
. These are great for setting the default value in a Date field, including the date in a Single Line Text field’s value, or including the date in a confirmation or notification. Anyone familiar with Gravity Forms has probably used them extensively. I know that I sure have.
With the release of Gravity Forms 2.6.1, a new merge tag has been added to expand on this feature: {today}
. The {today}
merge tag allows you to insert the current date or time into all of the same places {date_mdy}
is supported.
This includes things like inserting the current time into a field. I like to do this with order forms or any form where I’m using Date Time Calculator to do time calculations.
Using the Merge Tag
Prerequisites
Confirm that you have Gravity Forms 2.6.1 installed and activated.
Merge Tags for the Current time
The {today}
merge tag’s default output is the current date, but with the addition of the :format
merge tag modifier, you can output the current time in various formats.
Merge Tag | Output |
---|---|
{today:format:h} | 12-hour format of an hour with leading zeros. |
{today:format:H} | 24-hour format of an hour with leading zeros. |
{today:format:i} | Minutes with leading zeros. |
{today:format:A} | Uppercase Ante meridiem and Post meridiem. |
Insert these into a Time field’s Default Value to automatically populate the current time into the Time field when the form is loaded.
Formatting Dates
The formatting options for the {today}
merge tag also work for the current date, giving you lots of flexibility for displaying the current date anywhere on your form, confirmations, or notifications.
Merge Tag | Output |
---|---|
{today} | March 15, 2022 |
{today:format:Y-m-d} | 2022-03-15 |
{today:format:m/d/y} | 03/15/22 |
{today:format:d/m/Y\ \a\t\ H\:i\:s} | 15/03/2022 at 08:18:11 |
{today:timestamp} | 1647332291 |
Taking It Further
There are numerous options for formatting the current date with {today}
, however those formatting options don’t apply to captured dates. For example, say you have a Date field on your form asking the user for their birth date. Use our Display Captured Dates in Any Format plugin to change the formatting for those captured dates. This gives you tons of flexibility in confirmations, notifications, or anywhere you want to output the Date field’s value using merge tags.
Hey Dave, trying the @{:5:format:Y} dynamic tag, and it’s not working. It returns the entire date field without executing the format command. Thoughs?
Hi Dan,
That format modifier works for current time merge tag. We have a snippet you can use to output selected dates in any format. Here’s the documentation with a link to the snippet and details on how it works. For your use case, the merge tag to get the year of the selected date will be like so; @{:5:Y}.
Best,
can this be used for current day like. Eg. Monday , Tuesday etc
Hi Mufutau,
You can use GF native merge tags natively.
To populate Today’s date, it would be {today}.
Best,
Gravity Forms 2.6.1 added support for the {today} merge tag which can handle all these use cases natively without any extra code (https://docs.gravityforms.com/today-merge-tags/). π₯³
These are the comparable tags:
{time_hh} = {today:format:h} {time_hh:12} = {today:format:h} {time_hh:24} = {today:format:H} {time_mm} = {today:format:i} {time_am_pm} = {today:format:A}
{today} has the added benefit of allowing you to format the current date any way you want, too:
{today} (March 15, 2022) {today:format:Y-m-d} {today:format:d-m-Y} {today:format:m/d/y} {today:format:d/m/y} {today:format:m-Y} {today:timestamp}
Dates/times a plenty!
Great stuff, Jake! I saw this new merge tag but based on the PR I had understood that Richard had removed the custom format support. Glad I was mistaken as without it the merge tag is very much neutered. π
We’ll update this article to spell out how the new {today} merge tag can be used for this use-case. π