Get exact age from datepicker?

@yisrael-wix Thank you, I have just tested and the following error is returned: Cannot read property ‘getFullYear’ of undefined ( in var age = programDate.getFullYear() )

I’m guessing it’s because programDate has been defined in a separate enclosed function?

So this is now an overview of the relevant snippets of code…

$w.onReady(function () {
    $w("#datePicker1").onChange((event) => {
        let newValue = event.target.value; // "new value"
        let age = getAge(newValue);
          console.log('age: ', age);
        if (age >= 18) {
              $w('#button1').enable();
          } else {
              $w('#button1').disable();
          }
    });
});


export function programSelectDropdown_change(event) {

 if($w('#programSelectDropdown').value==='Soccer') {
        $w('#soccerRegistrationBox').expand();
    } else {
        $w('#soccerRegistrationBox').collapse();
    }

 let itemObj = $w("#programsDataset").getCurrentItem();
 let programDate = itemObj.coedSpringStart
        console.log("program date:",programDate)

}


function getAge(dateString, programDate) {
 var birthDate = new Date(dateString);
 var age = programDate.getFullYear() - birthDate.getFullYear();
 var m = programDate.getMonth() - birthDate.getMonth();
 if (m < 0 || (m === 0  &&  programDate.getDate() < birthDate.getDate())) {
         age--;
     }
 return age;
}