Hello,
My name is Carrie and I’m fairly new to Java Script. I used the below script in order to calculate and pipe in the last Sunday (past 7 days) for a timeline follow back that participants will be completing on Sundays. This worked great since the survey is always calculating 7 days from the most recent Sunday. However, for a new survey I’m building, I want the script to define the past 7th day from whenever the participant first opens the survey. Participants will be completing this survey from home, so the day will vary depending on when they start the survey. I also need the past 7th date to remain the same regardless if they open the link on a Monday and then again on Tuesday to complete. I tried the generic qualtrics piping but, that date recalculates using the current day, which means the dates change every time the participant clicks on the link. Is there a way to revise the code for what I’m needing? Thank you!
var d = new Date();
var lastSun = new Date();
lastSun.setDate(lastSun.getDate()-7-d.getDay());
var dd = lastSun.getDate();
var mm = lastSun.getMonth()+1;
var yyyy = lastSun.getFullYear();
if(dd<10) {
dd='0'+dd;
}
if(mm<10) {
mm='0'+mm;
}
lastSunNew = mm+'/'+dd;
Qualtrics.SurveyEngine.setEmbeddedData("1",lastSunNew);