Scott Ryer
/Updated January 10, 2023 /6 Comments
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.
- Insert the Current Time into Fields
- Using the Merge Tag
- Prerequisites
- Merge Tags for the Current time
- Formatting Dates
- Taking It Further
Using the Merge Tag
Prerequisites
Confirm that you haveGravity Forms 2.6.1installed 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.
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 47+ essential add-ons for Gravity Forms with support you can count on.
View All PerksBuy Now
- See AlsoGravity Forms: Populating fields dynamically (the ultimate guide)How to populate Simply Schedule Appointments data anywhere in Gravity Forms Gravity Forms Notification SchedulerHow to Style Forms in Gravity Forms: Ultimate Guide
Dan LinstedtFebruary 8, 2024 at 4:26 pm
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?
Reply
Samuel BassahStaffFebruary 9, 2024 at 10:05 am
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,
MufutauApril 29, 2022 at 1:42 pm
can this be used for current day like. Eg. Monday , Tuesday etc
Reply
Dario SpaceStaffApril 29, 2022 at 2:03 pm
Hi Mufutau,
You can use GF native merge tags natively.
To populate Today’s date, it would be {today}.
Best,
Jake JacksonApril 13, 2022 at 6:40 pm
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!
Reply
David SmithStaffApril 13, 2022 at 8:20 pm
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. 👍
Leave a Reply
Recent Posts
- Gravity Wiz Weekly 223
- Spotlight: Building a Self-managed Lawyer Directory using Entry Blocks
- Gravity Wiz Weekly 222
- Workshop IX: Unlock Entry Blocks
- Gravity Wiz Weekly 221
Categories
- How To(96)
- News(26)
- Plugins(22)
- Releases(31)
- Resource(5)
- Snippets(54)
- Spotlights(32)
- Tutorials(76)
- Updates(223)
- Workshops(4)
You might also like...
Post
How to Use Ready Classes in Gravity Forms
Read More
Post
Gravity Forms Field Value Extraction Techniques
Read More
Post
Read More