I am creating a registration form that requires entering a child’s birthdate as a form field question. Based on the birthdate, I want to use branch logic to direct them to other parts of the form. For example, if the birthdate is between 09/02/2022 and 09/01/2023, I want to branch to the Pre-K portion of the form, etc. Since there is no option for branching before or after a date, I am trying to use “greater than or equal to” and “less than or equal to”. But since the entry is a date and not a number, this is not working. How do I fix this or convert the form field date to a number to use branch logic?
Convert a date to a number
Best answer by Romanoman
To follow your requirement a bit more and also use JS as least as possible, I tried the approach below. The precondition is a date field with US format, and validation of the format done in the Qualtrics field itself.
On the form field question, I added this JavaScript:
Qualtrics.SurveyEngine.addOnPageSubmit(function () {
const el = document.getElementById('form-text-input-QID7-1');
const raw = (el && el.value ? el.value.trim() : '');
const m = raw.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/); // MM/DD/YYYY
if (!m) { Qualtrics.SurveyEngine.setJSEmbeddedData('DateISO', ''); return; }
// destructure the US format + leading zeroes added
let [, mm, dd, yyyy] = m;
mm = mm.padStart(2, '0');
dd = dd.padStart(2, '0');
// build YYYYMMDD format for easy comparison
const iso = yyyy + mm + dd;
Qualtrics.SurveyEngine.setJSEmbeddedData('DateISO', iso);
});What it does is it takes the US date that was typed-in by a respondent into “form-text-input-QID7-1” (this needs to be replaced by your form field ID), and transforms it into international standards without dashes (YYYYMMDD), just a number, e.g. 20220903.
Then I had to add an embedded field with this date (__js_DateISO) into the survey flow:

the __js_* prefix seems to be needed to make it work afterwords in the survey flow.
But then I was able to use the date in any way possible, use it as a piped text, for conditions, etc.
It should be easily reusable as long as you know the ID of the form field element, that can be acquired by inspecting the element in source code of the page, e.g. right clicking and using inspect in Chrome:

As an alternative, usage of the Calendar question type in the New survey taking experience is way easier - there you can directly grab the value in the international format too, and it can be used for a comparison like this one without any javascript.
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.







