Custom code to calculate date difference? | XM Community
Skip to main content
Solved

Custom code to calculate date difference?

  • June 16, 2023
  • 1 reply
  • 197 views

praveengeorgeix
QPN Level 4 ●●●●
Forum|alt.badge.img+11

Hi All,

There are 2 date variables. 1st date variable name is "TagShowDate" and the 2nd is "TagCurrentDate". Both variblae date format is "YYYY-MM-DD". There is hidden question created in survey named "DateBasedScreen" with 2 answer codes names "Yes" and "No".

Im looking for a code to check whether "TagShowDate" is greater than the last day of the month of "TagCurrentDate" then "DateBasedScreen" is "Yes" else "No"

Qualtrics.SurveyEngine.addOnload(function() {

var TagShowDate = "${e://Field/TagShowDate}";
var TagCurrentDate = "${e://Field/TagCurrentDate}";
var lastDayOfMonth = new Date(TagCurrentDate.getFullYear(), TagCurrentDate.getMonth() + 1, 0);
var DateBasedScreen = "${e://Field/DateBasedScreen}";

if (new Date(TagShowDate) > lastDayOfMonth) {
Qualtrics.SurveyEngine.setEmbeddedData('DateBasedScreen', 'Yes');
} else {
Qualtrics.SurveyEngine.setEmbeddedData('DateBasedScreen', 'No');
}

});

 

The above code is something which I created serching in internet. This is nt working. Could someone help with this?

 

Thank you,

Praveen

Best answer by Deepak

Answered here (Screen out based on embedded date variable and current month | XM Community (qualtrics.com))

1 reply

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • Answer
  • June 16, 2023