Java for converting minutes to hours | XM Community
Skip to main content
Solved

Java for converting minutes to hours

  • April 18, 2019
  • 2 replies
  • 117 views

Forum|alt.badge.img+1
Hello, I have a value of minutes (the answer of QID1). And if this value is over than 60, I want to convert this to hours and minutes. Qualtrics.SurveyEngine.addOnReady(function() { var hours = parseInt(("${q://QID1/ChoiceTextEntryValue}") / 60); var mins = parseInt(("${q://QID1/ChoiceTextEntryValue}") % 60); var t1; if(hours = 0){ t1 == mins; } Qualtrics.SurveyEngine.setEmbeddedData("t1", mins + " minutes"); else if(hours >= 1){ t1 == hours; } Qualtrics.SurveyEngine.setEmbeddedData("t1", hours + " hours " + mins + " minutes"); }); The problem is the "else if" part. I know the current code is wrong because it is showing only hours. Could anyone help me correct this code? Thank you very much in advance.

Best answer by Anonymous

Hello @jhwang , Here is the updated code: var hours = parseInt(("${q://QID1/ChoiceTextEntryValue}") / 60); var mins = parseInt(("${q://QID1/ChoiceTextEntryValue}") % 60); if(hours == 0){ Qualtrics.SurveyEngine.setEmbeddedData("t1", mins + " minutes"); } else { Qualtrics.SurveyEngine.setEmbeddedData("t1", hours + " hours " + mins + " minutes"); }

2 replies

  • 0 replies
  • Answer
  • April 18, 2019
Hello @jhwang , Here is the updated code: var hours = parseInt(("${q://QID1/ChoiceTextEntryValue}") / 60); var mins = parseInt(("${q://QID1/ChoiceTextEntryValue}") % 60); if(hours == 0){ Qualtrics.SurveyEngine.setEmbeddedData("t1", mins + " minutes"); } else { Qualtrics.SurveyEngine.setEmbeddedData("t1", hours + " hours " + mins + " minutes"); }

Forum|alt.badge.img+1
  • Author
  • 22 replies
  • April 18, 2019
@Shashi Perfect! Thanks a lot!