ConfirmIt Calculate age using birth date

Use the script code below to set the age question (Q2) based on the birth date question (Q1).

//surveyscripting.com

Out this in Q1 to validation the date format:
var date = IsDateFmt(f('Q1').get(),'DD/MM/YYYY');
if (!date){
  RaiseError();
  SetErrorMessage(CurrentLang(), "Please use the following format: DD/MM/YYYY.");
}

function yearsOld(){
  var d = f('Q1').get();
  var day = parseInt(d.substr(0,2));
  var month = parseInt(d.substr(3,2))-1;
  var year = d.substr(6,4);
  var birthday = new Date(year,month,day);
  var today = new Date();
  var years = today.getFullYear() - birthday.getFullYear();
  birthday.setYear(today.getFullYear());
  if (today < birthday) {
    years-- ;
  }
  return years;
}
//usage of the function:

f('Q2').set(yearsOld());