title: Formik & Yup: How to validate if the provided date is eighteen years old?
body: <p>I am working on a form that is made with Formik, Yup, and ReactJS. In the date field, I am trying to validate if the user is 18 years old. I have passed the following as validationSchema paremeter in Formik:</p>
  <pre><code>import differenceInYears from &quot;date-fns/differenceInYears&quot;;
  ...
  ...
  ...
      dob: Yup.date()
                .nullable()
                .test(&quot;dob&quot;, &quot;Should be greater than 18&quot;, function (value) {
                  return differenceInYears(value, new Date()) &gt;= 18;
                }),
  </code></pre>
  <p>The name of the formik input field is <code>dob</code>. But it shows the validation error even if I enter a valid date which is 18 years old. So, how to validate it properly?</p>