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

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

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


Thanks for your feedback.

I found a solution, I used Javascript 

 

Thanks a lot.

 

Quentin


Leave a Reply