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!
Page 1 / 1
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.
Search the Community for other posts about moment.js.
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")`.
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
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.