I want to calculate the difference in years between 2 dates. I have the current date stored in a variable using the new Date date object. The second date comes from a user input, which I am attempting to convert to a date object to be able to calculate the difference with getFullYear. However, I cannot get the value from user input into a date object. Console log returns ‘invalid date’.
Here is my latest code:
export function dob_change(event) {
const today = new Date();
A = $w("#dob").value;
B = new Date(A);
$w("#age").value = today.getFullYear() - A.getFullYear();
}
Any advice much appreciated.