Calculating the age of a subject
The following function calculates the exact age (in whole numbers):
var ret;
if(BRTHDAT != null && RFICDAT != null){
if(BRTHDAT <= RFICDAT){
ret =(RFICDAT.getFullYear()-BRTHDAT.getFullYear()) - 1;
if((BRTHDAT.getMonth() < RFICDAT.getMonth()) || (RFICDAT.getMonth() == BRTHDAT.getMonth() && BRTHDAT.getDate() <= RFICDAT.getDate())){
ret++;
}
}
return ret;
}
return null;
If using the Reference Data feature, beware of having an age that is between ranges. For example, an age of 18.5 will be between the ranges 0-18 and 19-45, and thus, neither range will apply.
For more details about functions and how to use JavaScript in Viedoc see lesson Using JavaScript in Viedoc.