Amend or recode Embedded Data Date field from mm/dd/yyyy to dd/mm/yyyy | XM Community
Skip to main content
Solved

Amend or recode Embedded Data Date field from mm/dd/yyyy to dd/mm/yyyy


Paul_Farrell
Level 2 ●●
Forum|alt.badge.img+5

Hi, 

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?

Thanks

Best answer by nikamshubham_73

Hi ​@Paul_Farrell,

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);
    
//Check on console
console.log("Day:", day);
console.log("Month:", month);
console.log("Year:", year);
console.log("Formatted Date:", FORMATTED_DATE);    

});

 

 

View original

2 replies

Forum|alt.badge.img+3

Hi ​@Paul_Farrell,

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);
    
//Check on console
console.log("Day:", day);
console.log("Month:", month);
console.log("Year:", year);
console.log("Formatted Date:", FORMATTED_DATE);    

});

 

 


Paul_Farrell
Level 2 ●●
Forum|alt.badge.img+5
  • Author
  • Level 2 ●●
  • 6 replies
  • March 10, 2025

Had to tweak the setembeddeddata tags slightly to work with new simple layout, but this worked great.Thanks!


Leave a Reply