Try a javascript action:
/**
* @param {Date} dateOfBirth
* @returns {Promise.<Big>}
*/
export async function GetAgeFromDateOfBirth(dateOfBirth) {
// BEGIN USER CODE
const currentYear = new Date().getFullYear();
const yearOfBirth = dateOfBirth.getFullYear();
return currentYear - yearOfBirth;
// END USER CODE
}
you can find it here https://forum.mendix.com/link/questions/1096
also there is a yearsbetween java action in the community commons