I have date of birth and I would like to calculate the age in a calc field. Is it possible ? I have tried with the following script :
Code: Select all
function ageCalc(birth,age_num) {
let o = $('#' + birth);
let d = nuFORM.removeFormatting(o.val(), o.attr('data-nu-format'));
var dob = new Date(d);
//calculate month difference from current date in time
var month_diff = Date.now() - dob.getTime();
//convert the calculated difference in date format
var age_dt = new Date(month_diff);
//extract year from date
var year = age_dt.getUTCFullYear();
//now calculate the age of the user
var age = Math.abs(year - 1970);
console.log('age='+age);
nuSetvalue('age_num',age);
}
I call this func as following
Code: Select all
ageCalc('pa_birthdate','pa_age');
Thanks,
Yves