How to do math operation in piped text for difference between two dates? | XM Community
Solved

How to do math operation in piped text for difference between two dates?

  • 15 May 2021
  • 3 replies
  • 220 views

Badge

I am having 2 embedded fields called Hire Date and Termination date and I wanted to calculate tenure through piped text. How to insert a piped text for this. Hire date and Termination date are in date formats where as the tenure should be in a number format like for example 10 years they are in the service.

icon

Best answer by Mishraji 16 May 2021, 03:58

View original

3 replies

Userlevel 4
Badge +18

You should be using JS for doing this. Following JS should work if difference in days is needed:

var hireDate = new Date("${q://QID1/ChoiceTextEntryValue/1}").getTime();
var terminationDate = new Date("${q://QID2/ChoiceTextEntryValue/1}").getTime();

    var diff = parseInt(terminationDate - hireDate);
    var days = diff/1000/60/60/24;
    Qualtrics.SurveyEngine.setEmbeddedData("Tenure", days);

Userlevel 5
Badge +11

Hi Mishraji,
Thanks for your code... I'm looking to do something similar but each day update an embedded field if another embeddedfield (eg. departure date) is within 1 day of today. If so, I'd update an embedded field (eg. Days to go) and then use an update ticket task and a ticket workflow scheduled email to send out a list to the relevent team.
Is there a way I could implement this code or something similar? My main problem is how you'd run through all responses and update those required. The new calulate metric task doesn't seem to handle dates and only works on NPS or averages. Also, creating a Formula embedded field in the data & analysis section also doesn't seem to handle dates either.

Any thoughts most welcome

Thanks

Rod Pestell

Badge +1

Hello,

This JS is perfect for US date formats (MMDDYYY). Has someone adapted it for the European date format DDMMYYY ? This would help. Thanks

Leave a Reply