How to Block a Date Range with Gravity Forms Datepicker

Easily disable a large range of dates from being selectable using GP Limit Dates with this handy filter.

This article requires the Gravity Forms Limit Dates perk.

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

View Plugin Buy Gravity Perks

GP Limit Dates provides an easy-to-use user interface for limiting selectable dates in a Gravity Form Date field. By default, we designed the user interface to give you complete control over the selectable dates.

But what if you wanted to select a large block of dates to disable? For example, the entire summer?

You could certainly go through manually and limit each day of the summer but this would take some time to do and besides, we have a better solution for you!

In this article, we will show you how to block a date range with Gravity Forms Datepicker.

How do I get started?

  1. Install and activate Gravity Forms, Gravity Perks, and GP Limit Dates.
  2. Copy and paste the snippet into your theme’s functions.php file.
  3. Modify the “Start Date” and “End Date” options at the top of the snippet to meet your needs. Full usage instructions are below.

Usage

Once installed, this snippet is easy to configure.

  1. Designate Your Date Field

    Replace the numeric values in the filter name with your Gravity Forms form ID (FORMID) and the Date field ID (FIELDID).

    gpld_limit_dates_options_FORMID_FIELDID

  2. Specify Your Date Range

    Find the $start_date and $end_date variables at the top of the code snippet. Replace each with the dates for your desired date range. The dates should be specified in the “YYYY-MM-DD” format.

    $start_date = '2016-07-15';
    $end_date   = '2017-01-01';

  3. Admire Your Handiwork

That’s all folks!

How’d that work for you? Leave us a comment below.

Comments

  1. Alice Manning
    Alice Manning August 25, 2023 at 3:16 pm

    I need to add this to two date fields on a form, one of which is conditional based on another question. Can you explain how to modify the php to include both date fields?

    Thanks!

    Alice

    Reply
    1. Scott Ryer
      Scott Ryer Staff August 25, 2023 at 3:59 pm

      Hi Alice,

      If those two date fields are the only date fields on the form, you can simply remove the _FIELDID portion from the gpld_limit_dates_options filter. Doing this will limit the date ranges for all date fields on the form.

      If you have more than those two date fields, you’ll need to duplicate the snippet and specify the FIELDID for both of the fields you want to apply this to.

  2. Jim
    Jim November 10, 2021 at 1:25 pm

    Is there a way to limit the date based on the selection from another form? I have 3 products that have a date selector. If one product is added to the cart, I want the other two products limited to the same date.

    Reply
    1. Dario Space
      Dario Space November 10, 2021 at 1:33 pm

      Hi Jim,

      You could probably mix this snippet with GP Populate Anything to get the value from the previous form and limit the dates based on that value.

      If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.

      Cheers,

  3. Lewis Robinovitch
    Lewis Robinovitch April 3, 2020 at 10:24 am

    How do I block off entire months indefinitely? For example, I would like to block off May, June, July and August from my date picker forever.

    Reply
    1. David Smith
      David Smith Staff April 6, 2020 at 6:33 pm

      Hey Lewis, just followed up with you on support. Let me know how the solution works for you. 🙂

    1. David Smith
      David Smith Staff September 18, 2019 at 12:29 pm

      Just set the start date to Jan 1st, 2021 and the end date to Dec 31, 2021.

      $start_date = '2021-01-01'; $end_date = '2021-12-31';

  4. arvind
    arvind June 14, 2019 at 2:43 am

    hy there

    Can I limit dates based on the value of another field?

    A simple eg: like if the Month of May is selected in a drop down-is there a way I can limit the date field to days of the month of May ie 01.05.2019 to 31.05.2019-is there away to achieve this? Thank you Arvind

    Reply
  5. arvind
    arvind June 14, 2019 at 2:42 am

    hy there

    Can I limit dates based on the value of another field?

    A simple eg: like if the Month of May is selected in a drop down-is there a way I can limit the date field to days of the month of May ie 01.05.2019 to 31.05.2019-is there away to achieve this? Thank you

    Reply
  6. Pascal
    Pascal February 25, 2019 at 1:22 pm

    Great feature, could you do the same for the other types of fields ? Exemple : Hide a text field after a certain date Exemple : mask certain item on a radio button field

    Reply
    1. David Smith
      David Smith Staff February 25, 2019 at 3:12 pm

      Yes, you can hide a Single Text Field after a certain date. You can’t remove a specific choice of a Radio Button field; however, you can have two Radio Button fields, one with the choice and one without, and use conditional logic based on the date to show the applicable version.

  7. Wan Zuhairi
    Wan Zuhairi February 16, 2019 at 5:30 am

    Hi,

    I just installed Date Picker. Why can’t i disable the whole week by unchecking all 7 days in ‘Days of the Week’ but include what ever dates i want to exclude? It would be easier if i want to disable all dates but to remain just few selectable dates.

    Reply
    1. David Smith
      David Smith Staff June 20, 2017 at 11:45 pm

      Hi Shane, yes, you can apply date limitations to each field. Let me know if you have any other questions. :)

  8. Michael
    Michael January 31, 2017 at 11:03 am

    I’m using the date picker to select an appointment date on my form where I don’t want people to be able to select holidays since we’re closed those days. I’m wondering if you’ve put any thought into making something like a predefined ‘black list’ to disable specific dates such as government holidays?

    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.

Download Snippet

How to Block a Date Range with Gravity Forms Datepicker

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