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

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

Leave a Reply