Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

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.

Last updated March 17, 2021 | Written by Scott Buchmann 8 Comments

This article requires the GP Date Time Calculator perk. Buy Gravity Perks today to get this perk plus 42 other premium Gravity Forms plugins!

  • View the 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.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 41+ essential add-ons for Gravity Forms with support you can count on.

  • View All Perks
  • Buy Gravity Perks

Filed Under: How To date field gp date time calculator product field

Comments

  1. math len says

    February 28, 2022 at 6:26 am

    Hello, is it possible to count the number of a certain day for example Monday between the two dates?

    Reply
    • Samuel Bassah says

      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,

    • Anthony D'Arco says

      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

    • Dario Space says

      August 3, 2022 at 6:08 pm

      Hi Anthony,

      We’ve already followed up via email.

      Best,

  2. Timothy Taylor says

    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 says

    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
    • Samuel Bassah says

      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 says

    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 Cancel reply

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

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

Recent Posts

  • Spotlight: Gravity Forms Media Library 🤝 Advanced Custom Fields
  • How ANM Powers Internal Finances with GP Unique ID
  • New Release: Gravity Forms QR Code Beta 1
  • How Farbie.at uses GP Inventory to manage over one thousand parties a year
  • Spotlight: Building a Loan Calculator with GP Advanced Calculations

Categories

  • How To (73)
  • News (25)
  • Plugins (19)
  • Releases (13)
  • Resource (3)
  • Snippets (50)
  • Spotlights (15)
  • Tutorials (57)
  • Uncategorized (4)
  • Updates (152)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2022 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Terms & Conditions of Use
  • Privacy Policy
  • Cookies Policy

Get access to hundreds of Gravity Forms plugins for free!

Enter your email and receive a list of our most popular free snippets and plugins for Gravity Forms.

  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account