Length of service | XM Community
Skip to main content

I am sending surveys to staff members and I have the date they joined the company (DOC) as an embedded field. Can I use this to calculate a filed which shows how long they have worked for the company. Ie to show date of survey minus DOC date as a number of months?

Thanks

You can use JavaScript and Luxon.  Load Luxon in the survey header:

<script src="https://cdn.jsdelivr.net/npm/luxon@3.4/build/global/luxon.min.js"></script>

Add this to a question (change startDate field name and date format as needed): 

Qualtrics.SurveyEngine.addOnload(function() {
var DateTime = luxon.DateTime;
var startDate = DateTime.fromFormat("${e://Field/startDate}","MM/dd/yyyy");
var tenure = DateTime.now().diff(startDate, e'months','days']).toObject();
Qualtrics.SurveyEngine.setEmbeddedData('tenure',tenure.months);
});

The field ‘tenure’ will be the number of months.


Leave a Reply