How to set dates using piped text around a fixed date with ${e://Field/Date} | XM Community
Solved

How to set dates using piped text around a fixed date with ${e://Field/Date}

  • 10 December 2018
  • 3 replies
  • 169 views

Hello Qulatrics community,

I am looking to use dates in basic calculaitons for display logic and validation. I have entered a static date (e.g., "Date" = 12/10/2018) into embedded data and attempted the code below, but the piped text shows up blank. I was told by qualtrics support to try the community to see if there is a way to modify a static date (not a moveable date like ${date://OtherDate/SL/-2%20day}) so that I can set a single date and then use code/syntax to update a series of other entries such as those below.

Response options:

Journal Entry 1 for ${e://Field/Date}
Journal Entry 2 for ${e://Field/Date+1}
Journal Entry 3 for ${e://Field/Date+2}
Journal Entry 4 for ${e://Field/Date+3}
etc.

I know that we can simply enter manually in every date, but with multiple data collections having a single or set of dates that I can enter where all other entries will be updated around them would be very helpful.

Thanks for any help you can provide!
icon

Best answer by fleb 10 December 2018, 22:55

View original

3 replies

Userlevel 7
Badge +27
I don't know how to do it with Qualtrics date piping. You could use JavaScript and moment.js. Just pipe your fixed embedded data date into the script, then have moment.js use it to calculate the other dates.

Search the Community for other posts about moment.js.
Userlevel 5
Badge +6
Hi @BFarmer,
I think you'll have to use javascript for that.

1) Convert your date from string to date datatype (more details here)
` var st = "${e://Field/Date}";`
` var dt = new Date(st);`

2) Create all new dates you need in the format you want to have in the text. More details here and here. I recommend writing a function for that.
` var dt2 = new Date();`
` dt2.setDate(dt.getDate()+1);`
` myString = dt2.getDate() + "/" + dt2.getMonth() + "/" + dt2.getFullYear();`

3) Use your new variables as you need. You can put them into embedded data fields using and then use the piped text to access them in following blocks. Or you can create HTML element containing these dates and append it to some question or put them to some question container (e.g.: `jQuery(this.getQuestionTextContainer()).append("Some text "+ myString + "Some other text")`.
Thank you @fleb and @TomG! I will need to read up on the links you sent, as I'm not yet familiar with using Javascript. I'm excited that it sounds like it can be done without too much hassle in javascript, and look forward to learning something new. Thanks again, and I'll report back how everything works in case others have a similar query.

Leave a Reply