Dear all,
For an international project I aim to adjust the piped text for different timezones. Specifically, I want to insert 'Yesterday, November 12th' based on the timezone of the participant rather than that of my account.
To this end, I have set up separate questionnaires for the three different timezones. Yet, I fail to set up a pipe that inserts the correct day depending on the location. To illustrate, my account is set to CET + 1 and a participant from the UK (CET + 0) opening the questionnaire at 11pm (CET + 0) will get the incorrect date using the following pipe: ${date://OtherDate/DM/-1%20day}.
Subtracting/ adding a constant value from the current time is possible when trying to adjust the time for different timezones (${date://OtherDate/G:i/+1%20hours}). However, it is not suitable for inserting the current/previous/... day.
Thanks for your help in advance,
Lukas
lg1 ,
I think you could pipe yesterday's ISO date ${date://OtherDate/c/-1%20day} into a JS date object, then use toLocaleString() to display it in the browser's local time and format.
https://community.qualtrics.com/XMcommunity/discussion/comment/43448#Comment_43448Thanks for your response. I am not familiar with using JS, could you give a demonstration on how to do this specifically?
https://community.qualtrics.com/XMcommunity/discussion/comment/43489#Comment_43489If your question has html something like this:
One day ago:
Then you can use JS like this to display yesterday's date and time:
Qualtrics.SurveyEngine.addOnload(function() {
var dateobj = new Date("${date://OtherDate/c/-1%20day}");
jQuery("#"+this.questionId+" .dayago").html(dateobj.toLocaleString());
});
https://community.qualtrics.com/XMcommunity/discussion/comment/43506#Comment_43506Thanks for you help. This returns something like " 08/02/2022, 16:45:51", how would I go about removing the time (--> 08/02/2022)?
https://community.qualtrics.com/XMcommunity/discussion/comment/43577#Comment_43577You can use toLocaleString options to format. However, since options is the second parameter you need to get the default locale to provide as the first parameter.
Qualtrics.SurveyEngine.addOnload(function() {
var dateobj = new Date("${date://OtherDate/c/-1%20day}");
var options = {year:'numeric',month:'numeric',day:'numeric'};
var locale = (new Intl.DateTimeFormat()).resolvedOptions().locale;
jQuery("#"+this.questionId+" .dayago").html(dateobj.toLocaleString(locale, options));
});
See Intl.DateTimeFormat() parameters for a full list of formatting options.
https://community.qualtrics.com/XMcommunity/discussion/comment/43581#Comment_43581Thanks again. When trying to create several dates (e.g., for yesterday, and two days ago (within the same question), this does not work:
Qualtrics.SurveyEngine.addOnload(function() {
var dateobj1 = new Date("${date://OtherDate/c/-1%20day}");
var options1 = {year:'numeric',month:'numeric',day:'numeric'};
var locale1 = (new Intl.DateTimeFormat()).resolvedOptions().locale1;
jQuery("#"+this.questionId+" .dayago1").html(dateobj.toLocaleString(locale1, options1));
var dateobj2 = new Date("${date://OtherDate/c/-2%20day}");
var options2 = {year:'numeric',month:'numeric',day:'numeric'};
var locale2 = (new Intl.DateTimeFormat()).resolvedOptions().locale2;
jQuery("#"+this.questionId+" .dayago2").html(dateobj.toLocaleString(locale2, options2));
});
- https://community.qualtrics.com/XMcommunity/discussion/comment/43583#Comment_43583You didn't update dateobj in dateobj.toLocaleString
- You only need to set locale and options once
- resolvedOptions().locale1 and .locale2 are invalid
- You need to update your html so the class names dayago1 and dayago2 match the JS (you didn't post this, so I don't know if you did it)
Corrected JS:
Qualtrics.SurveyEngine.addOnload(function() {
var dateobj1 = new Date("${date://OtherDate/c/-1%20day}");
var dateobj2 = new Date("${date://OtherDate/c/-2%20day}");
var options = {year:'numeric',month:'numeric',day:'numeric'};
var locale = (new Intl.DateTimeFormat()).resolvedOptions().locale;
var q = jQuery("#"+this.questionId);
q.find(".dayago1").html(dateobj1.toLocaleString(locale, options));
q.find(".dayago2").html(dateobj2.toLocaleString(locale, options));
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.