I have an ED field with a date, how do I make a new ED field with just the year from that date? | XM Community
Question

I have an ED field with a date, how do I make a new ED field with just the year from that date?

  • 24 September 2018
  • 4 replies
  • 45 views

Userlevel 6
Badge +5
Basically I have an ED field for date that is in this format MM/DD/YYYY. I would like to create a new ED field that just contains the YYYY portion of the first ED field so I can do a results report breakout by Year. Can this be done in Qualtrics or do I need to export to Excel then import?

4 replies

Userlevel 6
Badge +18
hey @uhrxx005 ,

since you are having date stored in embedded variable.
You can use split function in javascript to get yyyy part.
Please check this link

Hope it helps
Userlevel 7
Badge +33
refer below post too

https://www.qualtrics.com/community/discussion/475/how-to-split-a-string-using-2-different-separators

`var dob_entry = getTextValue();
var split_dob = dob_entry.split("/");
var month = split_dob[0];
var day = split_dob[1];
var year = split_dob[2];`
Userlevel 7
Badge +20
You will first have to create an embedded data "CurrentYear" in survey flow and then add below code in JavaScript part "onReady" section

var CurrentYear1 = "${date://CurrentDate/SL}";
CurrentYear1 = CurrentYear1.split("/");
var CurrentYear2 = CurrentYear1[2];
Qualtrics.SurveyEngine.setEmbeddedData("CurrentYear",CurrentYear2);
Badge +6
Alternatively you can change the type of embedded variable to Date (see screenshot below). By doing this you can see this variable for breakdown options of reports.


!

Leave a Reply