Extracting day of the week and month name as embedded data from answer | XM Community
Solved

Extracting day of the week and month name as embedded data from answer

  • 19 April 2024
  • 2 replies
  • 25 views

Badge +2

I have a question in a survey asking the date of the class. I have the default choice as today ${date://CurrentDate/SL} How can I create an embedded data field for the Day of the Week and Month name from this response?

icon

Best answer by vgayraud 19 April 2024, 10:23

View original

2 replies

Userlevel 6
Badge +38

Hi @SandraH ,

Create 2 EDs in your survey flow named selectedDay and selectedMonth and add this code to your question.

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{

const date = new Date(jQuery("#"+this.questionId+" .InputText").val());
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Qualtrics.SurveyEngine.setEmbeddedData('selectedDay', days[date.getDay()]);
Qualtrics.SurveyEngine.setEmbeddedData('selectedMonth', months[date.getMonth()]);

});

 

Badge +2

Thank you so much!

Leave a Reply