Hi TomG ,
I have tried this technique to pipe my question text into the formula and it is not working. Am I doing something wrong? I want the number of days between someone's last visit to campus
(${q://QID61/ChoiceGroup/AllChoicesTextEntry}), and the current date. This is what I have:
var start = new Date(${q://QID61/ChoiceGroup/AllChoicesTextEntry}),
end = new Date(),
diff = new Date(end - start),
days = diff/1000/60/60/24
I put this in the Set Embed Data portion of the survey flow:

https://www.qualtrics.com/community/discussion/comment/32778#Comment_32778The code is JavaScript. You have to add it to a question using "Add JavaScript..."
Hi
https://www.qualtrics.com/community/discussion/comment/32778#Comment_32778Hi TomG ,
That was helpful, but I'm still not seeing how that results in the number of days between the date.
var start = new Date(${q://QID61/ChoiceGroup/AllChoicesTextEntry}),
end = new Date(),
diff = new Date(end - start),
days = diff/1000/60/60/24
When I enter this into the JS editor, I keep getting errors.I am using the Piped Text option to embed the Question ID into the var start parentheses. I remove the curly bracket, and then it says to remove the :. I remove that, and it says to remove the close curly bracket. It seems like it doesn't want any of the piped text for the question.
All I want is for the question to display a number, like 4 if the last time I was on campus was 12/13/20 and today is 12/17/20. I will then make that number question invisible and only view it as part of the dashboard on the backend.
The piped text has to be in quotes, such as "${q://QID61/ChoiceGroup/AllChoicesTextEntry}"
Similar question here except I'd like the difference between dates to be set as embedded data. So in Survey Flow, I created the "Days" embedded data field and applied the following js to my survey question (QID190). However, the "Days" column is not populating when I run preview tests. Can you help me identify my error(s)?
Is there a way to calculate this field with survey data already collected. I would like to know the difference in days between two dates as an indicator in a dashboard ... Thank you
I'm not a coder, I don't know javascript - but I am pretty savvy and can make things work but maybe the bigger question is why do we need these skills for things like a date field - I recently had to create a date/time field and was looking for someone to provide step by step instructions on how to do that - I got it figure out but why did I have to go through all that effort? I spent way too much time on this - now I need to calculate the number of days between the two fields - again - need to spend way to many hours trying to figure this out. If its a number or date field you should be able to EASILY create a calculation - this isn't rocket science and other survey platforms offer it - so Qualtrics - why can't you create a date field type or a date/time field type for every day users and make things easy?
https://community.qualtrics.com/XMcommunity/discussion/comment/46538#Comment_46538You should submit a product idea and/or vote for existing product ideas that address date calculations.
TomG - thanks - I've submitted as an product idea
Hi spreik1 , if you still need, I have a QSF with examples of calculations between 2 date fields in days. Will just want to update the QIDs in the JS and survey flow for what matches your questions.
DateCalculations_Days.qsf
Hi everyone, Is there a way to calculate this field with two embedded fields Like date1 and date2, instead of two questions? Thank you!
Hi ManuelaPosso13
Have you test this calculation in your surveyflow with piped text ?
$e{ ${q://QID?(DATE2)/ChoiceTextEntryValue} - ${q://QID(DATE1)/ChoiceTextEntryValue} }
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.