# Age validation specific date \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545>\
**Category:** Get Help\
**Tags:** gravity-wiz, gform\_field\_validation, age, minimum-age\
**Created:** [July 17, 2023, 6:28pm UTC](https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545 "2023-07-17T18:28:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user640a3df029020682](https://avatars.discourse-cdn.com/v4/letter/u/f9ae1b/32.png) [@user640a3df029020682](https://community.gravityforms.com/u/user640a3df029020682)\
**Post date:** [July 17, 2023, 6:28pm UTC](https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545/1 "2023-07-17T18:28:58Z")

</div>

Hi all,

We just started with Gravity Forms and I love how the community is interacting and writing solutions as an extension of the well-written docs.

Now, we’ve just implemented a form with the age validation check written in this document: [https://docs.gravityforms.com/gform\_field\_validation/#h-13-date-field-age-validation](https://docs.gravityforms.com/gform_field_validation/#h-13-date-field-age-validation). As the user signs up for an event on a specific date, I am wondering if the age validation can be edited to ‘the event date’.

E.g. the event is on the 03 of September 2023 and the attendee must be 18 on the event date, when signing up for this event he isn’t 18 yet, but on the event date, this person is. How can we manage to check the age based on the age validation hook?

Sincerely,  
Matthijs

---

<div class="post-metadata">

**Author:** ![Morgan\_Kay](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/morgan_kay/32/3239_2.png) [@Morgan\_Kay](https://community.gravityforms.com/u/Morgan_Kay)\
**Post date:** [July 18, 2023, 11:03pm UTC](https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545/2 "2023-07-18T23:03:28Z")

</div>

Hi, Matthijs!

There is just one line you need to change to do what you want. In the line that has `new DateTime()`, you can just insert the date you want. So in your case, you would change the code snippet to this:

```auto
add_filter( 'gform_field_validation_10_2', function ( $result, $value, $form, $field ) {
    if ( $result['is_valid'] ) {
        if ( is_array( $value ) ) {
            $value = array_values( $value );
        }
        $date_value = GFFormsModel::prepare_date( $field->dateFormat, $value );
  
        $today = new DateTime( '2023-11-03` );
        $diff = $today->diff( new DateTime( $date_value ) );
        $age = $diff->y;
  
        if ( $age < 18 ) {
            $result['is_valid'] = false;
            $result['message'] = 'Underage';
        }
    }
  
    return $result;
}, 10, 4 );

```

Let me know if that doesn’t do what you need!

---

<div class="post-metadata">

**Author:** ![user640a3df029020682](https://avatars.discourse-cdn.com/v4/letter/u/f9ae1b/32.png) [@user640a3df029020682](https://community.gravityforms.com/u/user640a3df029020682)\
**Post date:** [July 19, 2023, 6:45am UTC](https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545/3 "2023-07-19T06:45:01Z")

</div>

Thank you so much for the explanation. I forgot quotes the other day, that explains why I got an error loading the whole website.

Thanks again!

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [July 20, 2023, 1:05am UTC](https://community.gravityforms.com/t/age-validation-specific-date-resolved/15545/4 "2023-07-20T01:05:02Z")

</div>

Closed on July 20, 2023, 1:05am UTC


