How can I compare options (times of day) to the current time? | XM Community
Skip to main content

I have a checkbox question with various times of day (12:30pm, 1:00pm, etc.) where users can sign up for a particular time for an appointment. I also have a date selector question. If the users selects today's date, I want to be able automatically remove times that have already passed, and ones that are too close to the current time. For example, if it is currently 10:55am, I want 9:00am, 9:30am, 10:00am, and 10:30am to not display. I also want 11:00am to not display since it is too close to the current time.
I am pulling the system time here:
 // get system time
 var d = new Date();
 var m = d.getMinutes();
 var h = d.getHours();
 if(h == '0') {h = 24}

   var currentTime = h+":"+m;

colsole.log('The current time is ' + currentTime + '.');
Is there a way to do this? Thank you!!

You can use this and change the conditions according to your need:
curr_time = h*60+m;
qid = this.questionId;
choice_contents = Qualtrics.SurveyEngine.QuestionInfo[qid].Choices;
options = [];
Object.entries(choice_contents).forEach(item => {options.push(item[1]);})


options.forEach((item) =>{
hr = item.Text.split(":")[0]*60;
if(item.Text.split(":")[1].includes("pm") && hr<720){hr +=720;}
mn = hr + Number(item.Text.split(":")[1].replace(/\\D/g,""));
if(mn })


Leave a Reply