Currently, I am utilizing moment.js to determine the difference between two dates in my Qualtrics survey. The following code has been effective thus far. The dates are formatted as YY-mm-dd, and ultimately, I receive the variance in days.
const duedate= Qualtrics.SurveyEngine.getEmbeddedData('duedate');
const daystodue = moment(duedate).diff(moment(new Date()), 'days', false);
Qualtrics.SurveyEngine.setEmbeddedData('daystill', daystodue );
An issue arises when I switch the format for the embedded data 'duedate'
from YY-mm-dd to ISO 8601 (for example, 2021-10-19T20:30:48Z) - this functionality ceases to work.
I understand that I may need to adjust the format for new Date()
to ISO as well, or convert 'duedate'
back to YY-mm-dd, but I am struggling to find a solution. Here is what I have attempted:
const duedate= Qualtrics.SurveyEngine.getEmbeddedData('duedate');
const daystodue = moment(duedate).diff(moment(new Date().format("YYYY-MM-DDTHH:mm:ssZ")), 'days', false);
Qualtrics.SurveyEngine.setEmbeddedData('daystill', daystodue );
I referred to this article for guidance, but as a novice in JavaScript, I am unable to make it function properly.
Any assistance would be greatly appreciated!