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 46 other premium Gravity Forms plugins!
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
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.
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.
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.
Hello, is it possible to count the number of a certain day for example Monday between the two dates?
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,
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
Hi Anthony,
We’ve already followed up via email.
Best,
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.
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.
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,
Hi David, I wonder if this addon works with the feature of calculating the target date with source date and user-specified date count?
This is what I want to do, seems strange its not possible.
Hi Tom,
This should be possible with our Populate Date Snippet. Checkout the documentation for details on how to use the snippet and the link to the snippet. https://gravitywiz.com/populate-dates-gravity-form-fields/
Best,