In the below example the field [CustomerDOB] is entered into the script in DD/MM/YYYY format, the [CustomerAge] will contain the age based on the date of birth entered. If the input box has the YYYY/MM/DD format then the commented section is not required.
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
// This section only required to change the dateformat
var dob = [CustomerDOB];
var result = dob.split("/");
dob = result[2] + '-' + result[1] + '-' + result[0];
[CustomerAge] = (getAge(dob));
Article ID: 1759, Created: August 18, 2016 at 11:35 AM, Modified: November 2, 2016 at 10:15 AM