Here is a working file for computing the Age from the DOB.
Note the formatting for the DOB field must be the same for the DOB field and the script.
Formatting of the entry is very important.
event.value = "";
// name for DOB field
DOB_field_name = "DOB";
// format for dob field
var cDateFormat = "dd-mmm-yyyy";
try {
var dobValue = getField(DOB_field_name).value;
} catch (e) {
app.alert("Error getting value of field " + DOB_field_name, 0, 1);
dobValue = "";
} finally {
if (dobValue!="") {
var dob = util.scand(cDateFormat, dobValue);
var today = new Date();
// compute years on full year only
var age = today.getFullYear() - dob.getFullYear();
// adjust for months after month of birth
if (today.getMonth() < dob.getMonth()) age--;
// adjust for today month equal to dob month and today's date after day of birth
if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate())) age--;
event.value = age;
} // end dobValue not empty
} // end get field value