Math operations and date field | XM Community
Solved

Math operations and date field

  • 14 May 2020
  • 4 replies
  • 405 views

Badge +2

Hello! I am building a scored survey as a mechanism to request and prioritize work from my department. Requestors input their project deadline date in the YYYY-MM-DD format.
One major factor in the prioritization process the length of time until the work is due.
I would like to be able to "score" the deadline date question based on a range of time until their selected date. I imagine I would need to use embedded data such as EndDate (when they finished the survey) and a math operation to determine # of days until the deadline date, and score it based on different timespan categories (i.e., 7 days until due date, 14 days, 28 days, 29+ days, etc.). Requests due sooner would then receive a higher prioritization score.
Is it possible to do this? Would the survey be able to use the "EndDate" embedded data while the survey is still in process? If anyone can help me with the code or math operation for this, that would be amazing!

Thanks!

icon

Best answer by mklubeck 17 June 2020, 18:14

View original

4 replies

Userlevel 7
Badge +27

To use math operations, you would need to convert your dates to YYYYMMDD in order to be able to add/subtract. That means you'll end up using JavaScript to do the conversion. Since you'll have to use JavaScript anyway, you might as well use moment.js to do the date calculations.

Badge +2

Thanks TomG
Any chance you could walk me through the process of using JavaScript? I'm an extreme newbie... 🙂

Userlevel 6
Badge +8

You all may want to look at this from The Ohio State University. https://u.osu.edu/advisingwithqualtrics/job-aids/populating-future-dates/

Userlevel 5
Badge +11

Hi @kjohnston,

Do you still need some help in getting started with JavaScript? there are a number of examples you can refer to which use flatpickr for example on this site to get you started but I totally agree there is not much documentation about how you refer to js libraries. Here are some pointers:

For flatpickr you have to use these lines in the header




For moment.js, see this: https://momentjs.com/docs/#/use-it/browser/
image.png
So, you need to put this in the header if I'm not mistaken

What I mean by header is in the look and feel of the survey there is a header field where you can put code in that runs on every page. Click edit and then click source, then paste the above in.

That will then let you refer to it in JavaScript for manipulating dates etc.

That's your first stage so hope that helps.

Thanks

Rod Pestell

Leave a Reply