# Sensible Year Range for Gravity Forms Date Drop-Downs

> Sets the years offered in Gravity Forms date drop-downs to a range that fits your form, such as the last 100 years for birth dates or the next two years for bookings.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, date, fields
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-date-year-range/

## Code

```php
$wpide_gf_years_back    = 100;
$wpide_gf_years_forward = 2;

add_filter( 'gform_date_min_year', function () use ( $wpide_gf_years_back ) {
    return (int) wp_date( 'Y' ) - $wpide_gf_years_back;
} );

add_filter( 'gform_date_max_year', function () use ( $wpide_gf_years_forward ) {
    return (int) wp_date( 'Y' ) + $wpide_gf_years_forward;
} );
```

## Notes

Applies to date fields using the drop-down input type; adjust how many years back and forward to offer.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Sensible Year Range for Gravity Forms Date Drop-Downs" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
