Check out the LimeSurvey source code on GitHub!

Easiest way to capture Time

More
3 years 1 week ago #105236 by dweisser
I have a survey where people are going to enter their time of arrival am or pm.
I'm having a hard time find a solution that doesn't entail some additional programming.
Anyone have an idea?
David

Please Log in to join the conversation.

More
3 years 1 week ago #105238 by dweisser
Update:
I implemented this. Simple enough. Now to try and get the AM or PM in there.
If anyone is interested, I'll be happy to post a step-by-step.
David

Please Log in to join the conversation.

More
3 years 1 week ago #105240 by byan
could you please share? Thanks!

Please Log in to join the conversation.

More
3 years 1 week ago - 3 years 1 week ago #105245 by dweisser
I used two short text questions to get Time Entered and Time left. And a third short text question to capture the TimeBetween.

First, I have to make sure they enter the times in a specific format so I can subtract Time Entered from Time Left.

Add the following regular expression to each TimeEntered and TimeLeft question's validation tip:
regexMatch("/^(?:[01][0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?$/",this)

This will ensure the respondent enters only valid times (01:15, 12:45) no invliad times (13:45, 22Lfty, etc.) DOES ANYONE KNOW HOW TO EDIT THE REGEX TO ALLOW THE LEADING ZEROES TO BE DROPPED?

Next, I put some javascript in template.js to do the math for TimeBetween. There's a much more eloquent way to write this, but I don;t know what it is. :-)
Be sure to change: #answer944284X236X1689 to your SurveyXGroupXQuestion identifiers. The code uses the answers to the first two questions in order to calculate the the third. It assign the calculation's result to the third items answer using an onchange event on the second answer. I made mine required to ensure that the event would be triggered.

$(document).ready(function(){
// Check if the answer is on this page...
$('#answer944284X236X1689').change(function(event) {
if($('#answer944284X236X1688').length > 0 && $('#answer944284X236X1689').length > 0) {
var StartTime = $('#answer944284X236X1688').val();
var EndTime = $('#answer944284X236X1689').val();

var s = StartTime.split(':');
if (s[0] > 6 && s[0] <= 12) {
var s= parseInt(s[0]) * 60 + parseInt(s[1]);
}
else {
var s= parseInt(s[0]) * 60 + parseInt(s[1]) + (12*60);
}

var e = EndTime.split(':');
if (e[0] > 6 && e[0] <= 12) {
var e= parseInt(e[0]) * 60 + parseInt(e[1]);
}
else {
var e= parseInt(e[0]) * 60 + parseInt(e[1]) + (12*60);
}

var TimeElapsed = e - s;
if(isNaN(TimeElapsed)){
document.getElementById('answer944284X236X1690').value= '';
}
else{
document.getElementById('answer944284X236X1690').value= TimeElapsed;
}

//alert(TimeElapsed);
}
})
});

I hope this is helpful.
David
Last Edit: 3 years 1 week ago by dweisser.
The following user(s) said Thank You: byan

Please Log in to join the conversation.

More
3 years 6 days ago - 3 years 6 days ago #105261 by dweisser
The REGEX statement above is for 24-hour time and doesn't suit the purpose.
Technically, you don't need it as long as respondents cooperate and enter valid 12-hour time. :P

I changed it to this:
regexMatch("/^(?:[1-9][0-2]|[1-9]):[0-5][0-9](?::[0-5][0-9])?$/",this)

Seems to work ok.
David
Last Edit: 3 years 6 days ago by dweisser.
The following user(s) said Thank You: byan

Please Log in to join the conversation.

More
3 years 6 days ago #105266 by mfaber
If you are using a recent 2.05 version, try adding a date/time question and enter HH:MM in the format field in the advanced attributes. Works with 24h-time format. Not sure about am/pm.

Screenshot for the timepicker at: manual.limesurvey.org/Question_type_-_Date
The following user(s) said Thank You: byan

Please Log in to join the conversation.

More
3 years 6 days ago #105267 by mfaber
Calculations SHOULD also work... try using {departuretime-arrivaltime} or whatever your question codes are named.
The following user(s) said Thank You: byan

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form