### [How to Limit the Years Inside Your Date Picker](https://wpforms.com/developers/how-to-limit-the-years-inside-your-date-picker/)

**Published:** May 20, 2020
**Author:** Editorial Team

**Excerpt:** Would you like to limit the years that show inside your date picker on your form? In this tutorial, we'll show you how to use JavaScript to achieve this. 

**Content:**

## Introduction

Would you like to limit the years that show inside your **Date Picker** form field? In this tutorial, we’re going to have the Date Picker limit the year to anything that is 18 years or above. Using PHP you can easily achieve this and we’ll walk you through each step.

## Creating the form

To begin, we’ll create a new form and add our fields which will include one **Date** field.

Once you add the **Date** form field, click on the **Advanced** tab and from the dropdown select **Date Picker** as the **Date Type**.

![](https://wpforms.com/wp-content/uploads/2020/05/wpforms-add-datepicker.jpg)

If you need any help in creating your form, [you can review this documentation](https://wpforms.com/docs/creating-first-form/ "How to Create Your First Form").

## Setup

Next, you’ll need to copy this snippet to your site.

If you need any help in how to add snippets to your site, [please check out this tutorial](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

```

/**
 * Limit years in date picker
 *
 * @link https://wpforms.com/developers/how-to-limit-the-years-inside-your-date-picker/
 */

function wpf_dev_limit_date_picker_years() {
?>

**Categories:** Tutorials

**Tags:** Javascript, JS

---

