Creating age groups based on yyyymmdd date of birth number | XM Community
Solved

Creating age groups based on yyyymmdd date of birth number

  • 10 May 2019
  • 1 reply
  • 31 views

Badge
Hoping someone already has an answer to this. I've got date of births coming in with the format yyyymmdd e.g. 19900805 and I want to get them into the following age groups:

15 years or less
16-19 Years
20-24 Years
25-29 Years
30-34 Years
35-39 Years
40-44 Years
45-49 Years
50+ Years

ATM our solution means the age groups created from DateofBirth will not be up to date next year. For example, someone born in in 2000, will be categorise in the 16-19 Age Group, next year it should fall in the 20-24 Age Group. But the nature of the variables feeding into Qualtrics do not allow for that automatic update.

Hoping someone might know how to create a more automated version! Any help would be great

Thanks
icon

Best answer by PeeyushBansal 10 May 2019, 04:51

View original

1 reply

Userlevel 7
Badge +33
You can use belo code to calculate age and than store in embed variable and create age brackets.

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var dob = '${q://QID57/ChoiceTextEntryValue}';
var year = Number(dob.substr(0, 4));
var month = Number(dob.substr(4, 2)) - 1;
var day = Number(dob.substr(6, 2));
var today = new Date();
var age = today.getFullYear() - year;
if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day)) {
age--;
}
alert(age);
});

Leave a Reply