how to extract Year from a birth date (Metadata) | XM Community
Skip to main content
Solved

how to extract Year from a birth date (Metadata)

  • February 28, 2024
  • 2 replies
  • 103 views

Forum|alt.badge.img+1

Hello,

I have a metadata BirthOfDate format (YYYY-MM-DD).

I need to create an embedded data based on this Birth Date to have only the Year of date. Embedded data YearBirth = YYYY

Could you please help me to do that ?

Thanks.

 

Quentin

Best answer by chackbusch

Hey @Quentin Goubert,

you would need at least one question before you need the year, e.g. like this: 

The two questions need to have a page break in between or need to be placed in two different blocks.

Within some question before the one you need the year in, you would need this JavaScript code (highlighted in the screenshot above): 

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
let birthDate = Qualtrics.SurveyEngine.getEmbeddedData( 'birthDate' );
let birthYear = birthDate.substring(0,4)
Qualtrics.SurveyEngine.setEmbeddedData( 'birthYear', birthYear );
});

In the survey flow, the setup should be like this: 

In my example, the piped text is correctly set: 

Hope it works for you as well. 

Best
Christian

2 replies

chackbusch
QPN Level 5 ●●●●●
Forum|alt.badge.img+22
  • QPN Level 5 ●●●●●
  • 415 replies
  • Answer
  • March 4, 2024

Hey @Quentin Goubert,

you would need at least one question before you need the year, e.g. like this: 

The two questions need to have a page break in between or need to be placed in two different blocks.

Within some question before the one you need the year in, you would need this JavaScript code (highlighted in the screenshot above): 

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
let birthDate = Qualtrics.SurveyEngine.getEmbeddedData( 'birthDate' );
let birthYear = birthDate.substring(0,4)
Qualtrics.SurveyEngine.setEmbeddedData( 'birthYear', birthYear );
});

In the survey flow, the setup should be like this: 

In my example, the piped text is correctly set: 

Hope it works for you as well. 

Best
Christian


Forum|alt.badge.img+1

Thanks for your feedback.

I found a solution, I used Javascript 

 

Thanks a lot.

 

Quentin