Skip to content

Instantly share code, notes, and snippets.

@marketinview
Created August 28, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marketinview/543413f36b34ba8bc71d97d4fd489b9d to your computer and use it in GitHub Desktop.
Save marketinview/543413f36b34ba8bc71d97d4fd489b9d to your computer and use it in GitHub Desktop.
Qualtrics: Age from Date of Birth #qualtrics #js #jq #age #birthdate #dob #luxon
<script src="https://cdn.jsdelivr.net/npm/luxon@3.4/build/global/luxon.min.js"></script>
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var DateTime = luxon.DateTime;
var birthDate = DateTime.fromFormat(jQuery("#"+this.questionId+" .InputText").val(),"MM/dd/yyyy");
var age = DateTime.now().diff(birthDate, ['years','months']).toObject();
Qualtrics.SurveyEngine.setJSEmbeddedData('age',age.years);
});
Age in years: ${e://Field/__js_age}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment