We have an embedded data field in a survey called EVENT_DT which states the date an appt took place, but the format in the sample file is set to mm/dd/yyyy. We wish to pipe this ED field into a question text, but have the format displayed as dd/mm/yyyy. Is this possible in any way as an embedded data function, or if not, possible via Javascript?
You can use the below JS code which splits the the initial date, and then add ups the date as per your requirement. IMPORTANT NOTE: Paste the code in any question BEFORE the pipein of the formatted date. For eg: if you are displaying formatted date in Q2, then paste the below code in Q1.
Code:
Qualtrics.SurveyEngine.addOnload(function() { /*Place your JavaScript here to run when the page loads*/
let EVENT_DT = "${e://Field/EVENT_DT}"; // MM/DD/YYYY format
// Split the date string let [month, day, year] = EVENT_DT.split("/");
// Ensure leading zeros remain day = day.padStart(2, '0'); month = month.padStart(2, '0');
let FORMATTED_DATE = day + "/" + month + "/" + year;
// Store values in Qualtrics Embedded Data Qualtrics.SurveyEngine.setEmbeddedData("DAY", day); Qualtrics.SurveyEngine.setEmbeddedData("MONTH", month); Qualtrics.SurveyEngine.setEmbeddedData("YEAR", year); Qualtrics.SurveyEngine.setEmbeddedData("FORMATTED_DATE", FORMATTED_DATE);
You can use the below JS code which splits the the initial date, and then add ups the date as per your requirement. IMPORTANT NOTE: Paste the code in any question BEFORE the pipein of the formatted date. For eg: if you are displaying formatted date in Q2, then paste the below code in Q1.
Code:
Qualtrics.SurveyEngine.addOnload(function() { /*Place your JavaScript here to run when the page loads*/
let EVENT_DT = "${e://Field/EVENT_DT}"; // MM/DD/YYYY format
// Split the date string let [month, day, year] = EVENT_DT.split("/");
// Ensure leading zeros remain day = day.padStart(2, '0'); month = month.padStart(2, '0');
let FORMATTED_DATE = day + "/" + month + "/" + year;
// Store values in Qualtrics Embedded Data Qualtrics.SurveyEngine.setEmbeddedData("DAY", day); Qualtrics.SurveyEngine.setEmbeddedData("MONTH", month); Qualtrics.SurveyEngine.setEmbeddedData("YEAR", year); Qualtrics.SurveyEngine.setEmbeddedData("FORMATTED_DATE", FORMATTED_DATE);