Disabling Future Dates in WPForms Date Time Field

 WPForms gives us the ability to disable selection of dates in the past however if you want to restrict dates in the future there isn't an option available for the field in the user interface.

That's not impossible to do but you will have to use a bit of jQuery to achieve that. And we will show you how. 

WPForms can be easily customized to your specific needs using jQuery, and in this case we will do the same - use a snippet of jQuery code to customize the date / time field. 

For this certain use case we are limiting dates in the future, it is particularly helpful in cases where you have a Date of Birth option and you don't want anybody to select a future date. 

Interestingly WPForms provides these snippets on their developer documentations but we noticed that it doesn't actually work well where you want to apply the settings only to a one specific field in your form. 


Don't allow Dates to be selected after a certain date


/**
 * Don't allow date to be selected after maxDate
 *
 * @link https://wpforms.com/developers/customize-the-date-time-field-date-options/
 */
 
function wpf_dev_limit_date_picker() {
    ?>
    <script type="text/javascript">
        window.wpforms_datepicker = {
            // Don't allow users to pick dates after Dec 31, 2025
            maxDate: new Date( '2025-12-31' )
        }
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_limit_date_picker', 10 );
Using the `new Date( '2025-12-31' )` in JavaScript we tell WPforms to not allow date after 12 December 2025 to be selected. 

However, this can be modified easily to disable selection of any future date, by simply using this


/**
 * Don't allow date to be selected after maxDate
 *
 * @link https://wpforms.com/developers/customize-the-date-time-field-date-options/
 */
 
function wpf_dev_limit_date_picker() {
    ?>
    <script type="text/javascript">
        window.wpforms_datepicker = {
            // Don't allow users to pick any dates after today
            maxDate: new Date()
        }
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_limit_date_picker', 10 );

Difference is that we don't pass anything in the `new Date()` constructor, that means it automatically picks the current date. 


But before you use the above snippets keep in mind that these will apply to all date / time field across all your WPForms on your website. 

To limit it to just a single field you will have to slightly modify the code, in the following section we will see how

Limit Date restriction only for a specific field


The following code applies our settings to only one field (id # 19)in a form with id # 2238

/**
 * Don't allow date to be selected after maxDate
 *
 * @link https://wpforms.com/developers/customize-the-date-time-field-date-options/
 */
 
function wpf_dev_limit_date_picker() {
    ?>
    <script type="text/javascript">
        window.wpforms_2238_19 = {
            // Don't allow users to pick any dates after today
            datepicker: { maxDate: new Date() }
        }
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_limit_date_picker', 10 );
`window.wpforms_2238_19` tells the browser to target only this one specific field and not any other.


Applying the code

In the above given snippets the JavaScript code is enclosed in a PHP code, that can be added to your theme files. We are not going to go into how to add PHP Snippets to your WP site, it is a long topic, but even if you aren't a developer yourself you can do that by using plugins like WPCode

It's an easy to use plugin that you can use to add PHP, HTML or other snippets to your WP Site. 

However, whichever way you use, either by adding the code to your theme files or using a plugin to add the snippets to your site, make sure it's added to the Footer for it to properly work. 

You can do much more

Disabling future dates in a Date / Time field is just one example, using the custom scripts you can modify it to achieve many different combinations of options, like allowing dates to allow only 18+ age DOB, or so on. Many of these are well documented on WPForms website.