Display or hide a block based on date parameters | XM Community
Skip to main content
I have a user who is looking to hide/display blocks of questions based on date parameters. I'm sure this is possible, but I'm having a hard time working it out in my head.



Anyone have any suggestions?
Can you tell us more about the date parameters? Where are they coming from? Are they absolute or relative? If absolute, what format are they in?
@TomG thanks for responding!

Yes, she wants to set up what essentially is one survey to allow people to register for these monthly seminars they have. She'd set up a block for each month's seminar, turning it on/off, depending on the date. E.g, If each seminar was on the 3rd of the month, for June, it would be open for registration from maybe May 20- June 1st. The other blocks within the survey for the July, August, etc events wouldn't be visible yet, nor would the blocks for past events be visible.



I was trying to think of a way to do it with embedded data and setting a value in survey flow, but Qualtrics doesn't allow you to do a custom date there and wasn't sure the best method.



Thoughts?
Since she is defining the dates (not user input or coming from someplace else), she could just use YYYYMMDD format and use them as numbers. To get the current date in that format use:

```

currentDate = ${date://CurrentDate/Y}${date://CurrentDate/m}${date://CurrentDate/d}

```

Then branch logic like the following (for the month of August):

```

If currentDate > 20180731 And currentDate < 20180901

```
Gah, I knew there was a way to do!! I completely forgot about branching! 😀 Thanks, @TomG . We'll have her give that a try.
@TomG I got so excited, I failed to ask if that currentDate code goes into the Survey Flow in an ED element? It doesn't seem to accept the full code string accurately so I'm assuming I'm putting it in the wrong spot or using the wrong element. 😕
Yes, currentDate goes in the survey flow as an ED element:

!
@TomG I figured it out!! 🙂 Thank you so much! Here's what I did with a throw-together test survey:

!
Hello! This answer & solution is very helpful and I'm using it myself. Would someone please tell me the significance of 'bytes' after the numeric date? Is that required for the solution? If not, what purpose does it serve?

Thank you!
@cjblakc, if I was to guess, I would say that the system reads the ED field of currentDate as a number and the bytes is just signifies the number quantity or type?
> @cjblack said:

> Hello! This answer & solution is very helpful and I'm using it myself. Would someone please tell me the significance of 'bytes' after the numeric date? Is that required for the solution? If not, what purpose does it serve?

> Thank you!



The bytes are a meaningless Qualtrics anomaly...those are integers. Evidently, they've cleaned it up because it doesn't show up anymore:

!
@MichelleC @TomG - Thank you!!! Very helpful.

TomG Related question, I think: Is it possible to capture the survey Start Date for similar branch logic? I'm working on a survey that I want to issue automatic retake links and conditionally shows blocks if today's date is X days after the Start Date, like a daily journal.
So, if the Start Date is 2020-08-01, only show block 3 if today is greater than or equal to 2020-08-03; but, Start Date could be 2020-08-10 for another user, so then only show block 3 if today is greater than or equal to 2020-08-12.


https://www.qualtrics.com/community/discussion/comment/28534#Comment_28534Yes, you can do that. Use the same embedded data assignment as above, and put it at the beginning of the survey flow.


TomG Sorry, I should clarify - by "Start Date," I mean I want to grab the response metadata for Start Date. Whenever a respondent first accesses the survey, I want to grab and store their unique start date, and then compare that date to Today to control when they're able to see the next block. So, when they come back to the survey through a retake link on another day, their session knows when that specific respondent started the survey, which could be different for each respondent. Does that make sense?


https://www.qualtrics.com/community/discussion/comment/28578#Comment_28578If you set a 'startdate' embedded data field at the very beginning of the survey flow as shown above, it will be the same as the metadata start date.


TomG But wouldn't the 'startdate' embedded data field as described update if they use a retake link on a later day? If they first access the survey on 08.01.2020, and then use a retake link on 08.05.2020, I want 'startdate' to be 20200801 in both instances.


Yes, if using a retake link. If using Save & Continue it would remain the same.
So, if you are using a retake link, you'll need to use some trickery to save the original start date. Perhaps you can use some JavaScript to answer a hidden question with the start date only the first time through the survey.


Hi TomG,
Just been looking through this thread and was hoping to take the numerical form one step further by adding hours and minutes (perhaps as a decimal). Do you know where there is a full list of syntax's for the CurrentDate function?

For instance, for hours I've tried these but they don't work.
${date://CurrentDate/h}
${date://CurrentDate/hh}

Thanks

Rod Pestell


https://www.qualtrics.com/community/discussion/comment/30954#Comment_30954No, I don't know where there is a full list of tokens for CurrentDate. It is an oddball; it doesn't match any other date/time library I've ever seen. I don't know if it is even possible to get hour and minutes separately.


Hi TomG
It sounds like I'll need to do something in a question then through Javascript.  I've never amended an Embedded field before, do you have a good Javascript example that could be used or point me to a post?  Invariably I'd then combine and format YYYYMMDD.HHMMSS, assign the embedded field as a number and then I should be able to filter my dashboards by a specific time of the day - happy days!!  :)  Qualtrics support said it wasn't possible (!)

To take this one step further, I'm trying to replicate the system field recorded date as close as possible. I guess it would be best to run the JavaScript at the end of the survey but not sure how this would play out for people who only half complete the survey and then Qualtrics completes it after time out - recorded date is added for all complete or incomplete surveys I see but would placing the code at the end still work?

Thanks

Rod Pestell


https://www.qualtrics.com/community/discussion/comment/30962#Comment_30962Define endTime at the beginning of the survey flow, then if the JS variable is also endTime:
Qualtrics.SurveyEngine.setEmbeddedData('endTime',endTime);
JavaScript at the end of the survey wouldn't run for an incomplete survey. You can put the script in the survey header or footer to update endTime on each page. I would put the script inside the Qualtrics.SurveyEngine.addOnPageSubmit() function.


EMA example Day 1.pngEMA example Day 2.pngI modelled my survey after Michelle’s screenshot above but can’t figure out how to distribute the separate groups (of blocks) on different days. It’s a time diary survey (EMA) for 30 days post Screener + Baseline. I decided to keep the entire thing in one survey because I need to pipe in at most 8 unique answers from the Screener + Baseline into the daily surveys (it’s a name generator); I tried linking surveys together and piping information via ED and ExternalReferenceData but it wasn’t working (followed the Qualtrics site).
Participants will provide up to 8 unique names in the Screener + Baseline and then we will ask if they’ve spoken to these individuals each subsequent day for 30 days. Although keeping the Screener + Baseline and EMA (time diary) components in 1 survey is complicated and a beast, it seemed to be the easiest way to ensure the names they provided were piped into the EMA portion each day.
Following Michelle’s survey flow, how do I send Group: Day 1 to participants (a group of blocks) one day, and then Group: Day 2 (duplication of Group: Day 1) the next day? We are sending the link via SMS and ideally want participants to receive a link every day. I saw other posts that mentioned the retake link but it looks as though that overwrites previous data and can be complicated. I can successfully send the link via SMS but I don’t know how to schedule the following blocks to be sent on different days.
The problem with creating a separate survey for the time diary portion and using the retake link option is I don’t think participants would be able to add new alters (names) to the survey, even if they did those names wouldn’t be piped into subsequent days (i.e., Day 1, participant adds a new name, then on Day 2 we ask them if they have spoken to any of their alters including the new ones). Once participants have indicated they’ve spoken to a new alter 3+ times, we ask additional questions about that person… so I don’t think the retake link would work for that? It’s a lot. TIA!


Leave a Reply