Calculate the Number of Days Between Two Dates With Gravity Forms

Calculate the number of days between two given date fields and populate this number into a field on the form.

This article requires the GP Date Time Calculator perk.

Buy Gravity Perks to get this perk plus 47 other premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

There’s plenty of scenarios where counting the number of days between two given date fields is useful in your forms. For example, you might have a form that’s used to register users for a multi-day event or you want to build a form for tracking the number of days an employee has been with your company. Whatever your use case, this tutorial will help you calculate the number of days between two dates with ease.

Gravity Forms Date Time Calculator adds support for date and time calculations in any Gravity Forms field that supports calculations. We can use it to accurately calculate the number of days between two date fields in our form.

Steps

  1. Add Start and End Dates
  2. Calculate the Number of Days

Step 1 – Add Start and End Dates

Add two Date fields to your form, name them “Start Date” and “End Date”, and set your desired date format.

Step 2 – Calculate the Number of Days

Add a Number field to your form and name it “Number of Days”. In the Formula box, subtract Start Date’s merge tag from End Date’s merge tag.

That’s all there is to it! You now have a Number field that dynamically displays the number of days based on user input in the Date fields.

Taking This Further

Conditional Discounts

You can do a number of interesting things now that you have this count. For example, you can show another field in the form using conditional logic based on the number of days counted. This has a variety of uses, like offering a discount once the customer has selected a minimum number of days.

You can use a similar technique to set up age-based pricing with GF Date Time Calculator. Check out the following tutorial on how to set that up:

How to Set Up Age Based Pricing

Variable Pricing

Using GF Advanced Calculations, you can set up variable pricing by adjusting a calculated Product field’s price based on the value on the Number of Days field.

GF Date Time Calculator isn’t just limited to calculating days. It can count in any time unit, such as years, weeks or months, using the Date Calculation Unit setting.

Questions? Comments?

Do you have any questions on setting this up? Do you have an interesting use case you’d like to tell us about? We’d love to hear them. Leave us a comment below.

Comments

  1. Andrew Legrand
    Andrew Legrand March 19, 2024 at 1:30 pm

    When does the calculation occur?

    I have a single-page form with the start date, and I’m trying to determine the number of days between the start date and today.

    The calculation is correct when the form is submitted, but I’m trying to add conditional logic for when the difference between the start date and today is less than 5 days.

    That field isn’t showing when I change the start date, and the number field I’m using to perform the calculation isn’t updating.

    I’ve tried moving the calculation to a separate page, but that didn’t change the conditional logic or appearance, either.

    Reply
    1. Scott Ryer
      Scott Ryer Staff March 19, 2024 at 4:26 pm

      Hi Andrew,

      Gravity Forms performs calculations in Number fields when any of the referenced field’s values are updated. It sounds like there might be something else at play, so I’m going to follow up via email and we can start troubleshooting this.

    1. Samuel Bassah
      Samuel Bassah Staff February 28, 2022 at 6:58 am

      Hi Math,

      This is currently not possible. If you have an active Gravity Perks License (Advanced or Pro), you can submit a ticket via our support form and we will forward this to our developers as a feature request to see if this can be supported.

      Best,

    2. Anthony D'Arco
      Anthony D'Arco August 2, 2022 at 3:23 pm

      I was wondering if this was ever resolved. We a rental unit that has a different price for weekends vs weekdays, but I want folks to be able to select an arrival/departure date, for instances:

      Arrive – Thursday | Depart Tuesday Weekdays – $100 Weekends – $150

      So, this would be Thursday + Sunday + Monday Nights = 3 x $100 =$300 Friday + Saturday = 2x $150 = $300 Total $600.

      If I’m able to count the number of days as described in Math Len’s question, I should be able to make the rest happen without issue. Let me know if this was ever resolved please.

      Thank you! Anthony

  2. Timothy Taylor
    Timothy Taylor January 13, 2022 at 6:42 pm

    Is there a way to use this with gv_math? I want to be able to calculate the difference between two dates on the fly. The problem I’m having with this current setup is that it only calculates on form submission, but not after a gravity view edit. gv_math support would solve this for me.

    Reply
  3. Ericus Steyn
    Ericus Steyn April 30, 2021 at 5:29 am

    I want the number of days calculated and displayed automatically i.e. number of days from May 1 2020 to TODAY.

    Is something like that possible? User must not enter anything. I know the start date and the end date will always be the current date.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff April 30, 2021 at 6:55 am

      Hi Ericus,

      This is possible. The GP Date Time Calculator Perk has a {today} merge tag that you can use within the calculation formula to get the difference between a date and the current date. With the Merge tags, you don’t have to manually enter the current date.

      Best,

  4. Edi Michael
    Edi Michael November 25, 2019 at 11:07 am

    Hi David, I wonder if this addon works with the feature of calculating the target date with source date and user-specified date count?

    Reply

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.