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.

  1. Insert the Current Time into Fields
  2. Using the Merge Tag
    1. Prerequisites
    2. Merge Tags for the Current time
  3. Formatting Dates
  4. Taking It Further

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 TagOutput
{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 TagOutput
{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.

Comments

  1. Dan Linstedt
    Dan Linstedt February 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
    1. Samuel Bassah
      Samuel Bassah Staff February 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,

  2. Jake Jackson
    Jake Jackson April 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
    1. David Smith
      David Smith Staff April 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

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

This field is for validation purposes and should be left unchanged.