Calculating the age of someone based off a date field (getAge())

The getAge() is a built-in system function that determines the current age of someone based on a date value on a form.

The following Script will calculate age when a date value is passed in from another field, i.e. from Person_DOB_dt.

This script will directly set the value of the field Person_DOB_scr with the age calculated off the field in which this field script is placed (i.e. $(this)):

// Set a field to an age when a date Form Field is changed, place this Script in the date Form Field:
fld('Person_DOB_scr').val(getAge($(this).val()));

You can also set the format of the date field that is passed into the getAge() function:

fld('Person_DOB_scr').val(getAge($(this).val(), 'dd/mm/yyyy'));

This function will set the value of the ‘age’ variable to the value of the getAge(). However, unless you specify the format of the date being passed into the getAge() function, it will assume that the field Person_DOB_dt is in a US-style date format, i.e. MM-DD-YYYY:

// This calculates an age based on the content of the date field.
var age = getAge(fld('Person_DOB_dt').val());