How to compare dates in Qualtrics | XM Community
Skip to main content

So, you want to compare today's date to a date entered in a response. Or you want to know if the date entered is more than one month from today. Or compare the start date to the end date entered to ensure they didn't mistakenly put in a wrong date.
It's all about validation. Qualtrics can do this natively IF the dates entered are all the exact same format.
image.pngIn survey flow I created a few embedded data fields to hold some data
1.     Is today’s date – the date the respondent is filling out your survey
2.     Tomorrow shows how to increment by one day. NOTE: %20 is html for a space
3.     Thirty days from now adds thirty days to today’s date
4.     Thirty days ago subtracts 30 days from today’s date
image.pngI can show the data...
I can even ask for a date input (has to match the format)
image.pngAnd then I can do a comparison between what was input and what I already have to control my display logic.
image.pngMy only issue/problem to solve now is how can I force the proper format needed (mm/dd/yyyy - with NO leading 0s for months or days)? I need help with REGEX that will validate no leading zeros for mm nor dd.


might as well also ensure that the day isn't greater than 31 and the month not greater than 12


Alright! Thanks to Dave B (coworker), I believe we also found REGEX to:

  1. check that there is no leading 0 on days

  2. check that there is no leading 0 on months

  3. ensure days don't go over 31 and months don't go over 12

^([1-9]|1[012])\\/([1-9]|[12][0-9]|3[01])\\/\\d{4}


This is incredibly helpful content - I know so many users have struggled with date calculations in the past. Thank you so much for sharing this thoughtful solution 😁


Thanks AmaraW I enjoy finding "native" solutions without coding. Coding runs into issues when the source controls change (javascript seems to change weekly) or if it collides with controls on the system or platform.


Looks like this no longer works? Anyone else noticing issues with comparing dates now? I'm going to look into creating a Julian-type value and compare as a number...


And now it's back to working!


It's working without designating Text Set
image.pngAnd within the project, the display logic works properly
image.png(Adult Pads 1 Exp Date - was a text entry field using date format yyyy/mm/dd). The constant is the date format AND that you compare a embedded data field (name) to an embedded data field (code)


Leave a Reply