- Posts: 9
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
calculate an intervention duration
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
10 years 10 months ago #96184
by ahchouch
calculate an intervention duration was created by ahchouch
0Hi
I need to calculate the duration of an intervention in minutes.
I have 04 numeric type questions standing for hour and minute of benginning and finish of intervention.
Q1: Hour of incision
Q2/ minute of incision
Q3: Hour of closure
Q4: minute of closure
How can i do this with EM or JS?
The main issue is to handle the negative difference between hours or minutes (IH 23 and CH 00 for instance witch should give 01 hour difference not -23!)
Thanks in advance
I need to calculate the duration of an intervention in minutes.
I have 04 numeric type questions standing for hour and minute of benginning and finish of intervention.
Q1: Hour of incision
Q2/ minute of incision
Q3: Hour of closure
Q4: minute of closure
How can i do this with EM or JS?
The main issue is to handle the negative difference between hours or minutes (IH 23 and CH 00 for instance witch should give 01 hour difference not -23!)
Thanks in advance
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
10 years 10 months ago #96185
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic calculate an intervention duration
I'm not sure if you already know that you can use as well a very smart
"timepicker" question
...
It's the end of the good news because I have no idea if it can be easier to handle your calculation with this
It's the end of the good news because I have no idea if it can be easier to handle your calculation with this
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
10 years 10 months ago #96187
by ahchouch
Replied by ahchouch on topic calculate an intervention duration
Thanks Ben
I actually kept my 4 numeric type questions and tried some JS.
I had first to set rules for calculating the duration according to hours and/or minutes of closure are superior or not hours and/or minutes of incision. (4 cases!)
It worked fine.
I just need to add an alert if one of the four fiels is empty. It seems simple but my knowledge of JS is less than basic!
Heres' the JS
I actually kept my 4 numeric type questions and tried some JS.
I had first to set rules for calculating the duration according to hours and/or minutes of closure are superior or not hours and/or minutes of incision. (4 cases!)
It worked fine.
I just need to add an alert if one of the four fiels is empty. It seems simple but my knowledge of JS is less than basic!
Heres' the JS
Code:
<script type="text/JavaScript"> jQuery(document).ready( function(){ // alert('onload alert!'); $('#answer941186X3X378,#answer941186X3X379,#answer941186X3X380,#answer941186X3X381').change(function() { var hoi= parseInt($('#answer941186X3X378').val()); var moi= parseInt($('#answer941186X3X379').val()); var hoc= parseInt($('#answer941186X3X380').val()); var moc= parseInt($('#answer941186X3X381').val()); var duree = new Number(); if ((hoc >= hoi) && (moc >= moi)) { duree = (60 * (hoc - hoi)) + (moc - moi); } if ((hoc >= hoi) && (moc < moi)) { duree = 60 * (hoc - hoi - 1) + 60 - moi + moc; } if ((hoc < hoi) && (moc < moi)) { duree = (60 * ((23 - hoi) + hoc)) + ((60 - moi) + moc); } if ((hoc < hoi) && (moc >= moi)) { duree = (60 * ((24 - hoi) + hoc)) + (moc - moi); } $('#answer941186X3X1341').val(duree); }); } ); </script>
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
10 years 10 months ago #96189
by Ben_V
Remember that in the advanced settings of numerical input questions you can use the 'question validation equation' and 'question validation tip' to display a validation message...
(!is_empty(1234X56X789.NAOK))
or any more complex rule...e.g.:
((!is_empty(1234X56X789.NAOK) && (1234X56X789.NAOK >= "0"))
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic calculate an intervention duration
Sounds like the 4 questions just have to be set 'mandatory' :blink:I just need to add an alert if one of the four fiels is empty.
Remember that in the advanced settings of numerical input questions you can use the 'question validation equation' and 'question validation tip' to display a validation message...
(!is_empty(1234X56X789.NAOK))
or any more complex rule...e.g.:
((!is_empty(1234X56X789.NAOK) && (1234X56X789.NAOK >= "0"))
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Attachments:
The following user(s) said Thank You: ahchouch
The topic has been locked.