The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD! List of donors »
|
-
Ben_V
-
-
OFFLINE
-
Platinum Lime
-
- Beiträge: 730
- Dank erhalten: 134
-
Karma: 43
-
|
Hi,
I would like to set a (hidden or not) question calculating the number of nights between 2 dates (patient hospitalization delay):
q1 (date question type) => Admission
q2 (date question type) => Discharge
q3 (numerical/equation) => xDays
Is there any way to do this using EM or JS ?
Thanks in advance for any help!
|
Benoît
goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
|
-
DenisChenu
-
-
ONLINE
-
Moderator Lime
-
- Beiträge: 4373
- Dank erhalten: 451
-
Karma: 165
-
|
Hello,
With 1.92, if you make date diff on a second page (to be sure to have SQL date).
You can try something like this: var DateDiff = {
inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000));
},
inWeeks: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000*7));
},
inMonths: function(d1, d2) {
var d1Y = d1.getFullYear();
var d2Y = d2.getFullYear();
var d1M = d1.getMonth();
var d2M = d2.getMonth();
return (d2M+12*d2Y)-(d1M+12*d1Y);
},
inYears: function(d1, d2) {
return d2.getFullYear()-d1.getFullYear();
}
}
d1 = new Date({substr(DD,0,4)}, {substr(DD,5,2)}, {substr(DD,8,2)});
d2 = new Date({substr(D2,0,4)}, {substr(D2,5,2)}, {substr(D2,8,2)});
document.write("<br />Number of <b>days</b>: "+DateDiff.inDays(d1, d2));
document.write("<br />Number of <b>weeks</b>: "+DateDiff.inWeeks(d1, d2));
document.write("<br />Number of <b>months</b>: "+DateDiff.inMonths(d1, d2));
document.write("<br />Number of <b>years</b>: "+DateDiff.inYears(d1, d2));Maybe there are other option with EM.
Denis
PS: DateDiff script from ditio.net/2010/05/02/javascript-date-difference-calculation/
PS2: DD is the code of the first date, D2 of the second date
|
Letzte Änderung: 6 Monate 5 Tage her von DenisChenu. Begründung: PS2
|
-
Ben_V
-
-
OFFLINE
-
Platinum Lime
-
- Beiträge: 730
- Dank erhalten: 134
-
Karma: 43
-
|
Merci Denis,
I will try to implement this asap and come back here for some feedback.
Thanks again.
Ben-
|
Benoît
goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
|
-
Ben_V
-
-
OFFLINE
-
Platinum Lime
-
- Beiträge: 730
- Dank erhalten: 134
-
Karma: 43
-
|
 working!
Now it will be great to add some validation
a) checking that DD date is always anterior than D2 (pretty important to avoid negative values)
b) setting a minimum starting date for DD, as "minimum year" does in advanced setting (could be current date )
Any idea?
Thanks
Note: LS original code for Minimum year:2012 & Maximum year:2014 <input type='hidden' name='dateyearrange123X456X789' id='dateyearrange123X456X789' value='2012:2014' />
|
Benoît
goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Letzte Änderung: 6 Monate 5 Tage her von Ben_V.
|
-
DenisChenu
-
-
ONLINE
-
Moderator Lime
-
- Beiträge: 4373
- Dank erhalten: 451
-
Karma: 165
-
|
benitov schrieb:
I attach a sample export if somebody wants to play with it  [/url] If you have time to fill the workaround part of docs.limesurvey.org/
|
|
|
-
Ben_V
-
-
OFFLINE
-
Platinum Lime
-
- Beiträge: 730
- Dank erhalten: 134
-
Karma: 43
-
|
Denis, no problem for completing the workaround but much better if i can previously find a solution regarding the validation (at least checking that 1st date is always anterior than 2nd one ...)
|
Benoît
goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
|
-
DenisChenu
-
-
ONLINE
-
Moderator Lime
-
- Beiträge: 4373
- Dank erhalten: 451
-
Karma: 165
-
|
Hello,
Review after posting, if survey date is set to dd.mm.yyyy, then:
<script>
$("#limesurvey").submit(function(){
DD = $("#question7490 input.popupdate").val();
D2 = $("#question11621 input.popupdate").val();
if(substr(DD,6,4)<substr(D2,6,4)){ return true; }
if(substr(DD,3,2)<substr(D2,3,2)){ return true; }
if(substr(DD,0,2)<substr(D2,0,2)){ return true; }
alert("D2 must be less than DD");
$("#limesurvey .submit").attr("disabled",false);
return false;
});
</script>AFter you can use some function like this:
A new question type "no answer" with: <div class="error" id="myerror"></div>
<script>
function testifOK(){
D1 = $("#questionQQ1 input.popupdate").val();
D2 = $("#questionQQ2 input.popupdate").val();
if(D1==""){$("#myerror").text("You have to select a date for D1");return false;}
if(substr(D1,6,4)<substr(D2,6,4)){$("#myerror").text("The date for D1 must be less than D1");return false;}
...
}
*
....* have to found a way to detect all change in datepicker
|
Letzte Änderung: 6 Monate 4 Tage her von DenisChenu. Begründung: *
Folgende Benutzer bedankten sich: Ben_V
|
-
Ben_V
-
-
OFFLINE
-
Platinum Lime
-
- Beiträge: 730
- Dank erhalten: 134
-
Karma: 43
-
|
Denis,
Can't get it working 
Settings:
dd.mm.yyyy
Gr1: the 2 date pickers
Gr2: numerical (not hidden for the moment) question + boilerplate with the first script (only qid changes)
Gr3: ...other questions of the survey
I don't understand how to handle your second block of js 
"A new question type "no answer" with..."
I think that I'll complete LS documentation right now... and updating it after in case of improvment...
Thank you for all
|
Benoît
goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
|
-
DenisChenu
-
-
ONLINE
-
Moderator Lime
-
- Beiträge: 4373
- Dank erhalten: 451
-
Karma: 165
-
|
benitov schrieb:
I don't understand how to handle your second block of js 
"A new question type "no answer" with..." Only the first part work ?
If yes, the second part is to launch some "information" at screen, but when i'm looking for blur or change , jquery ui calendar son't launch this .
Actually, you can do the job at "submit" only.
I have to found how to detect the date was changed.
Denis
|
|
|
|