Page:12

## Calcul based on 2 dates 1 year 3 weeks ago #88134

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 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... The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88157

 DenisChenu NOW ONLINE Moderator Lime Posts: 5151 Thank you received: 582 Karma: 199 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("
Number of days: "+DateDiff.inDays(d1, d2)); document.write("
Number of weeks: "+DateDiff.inWeeks(d1, d2)); document.write("
Number of months: "+DateDiff.inMonths(d1, d2)); document.write("
Number of years: "+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 Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development Last Edit: 1 year 3 weeks ago by DenisChenu. Reason: PS2 The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88160

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 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... The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88168

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 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`` 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... Last Edit: 1 year 3 weeks ago by Ben_V. The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88202

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 I attach a sample export if somebody wants to play with it and 2 more or less related links to previous posts: "Calculate age in an Equation type question, using Date of Birth" "Default Date" Attachments: Date_calcul.lss (23KB) 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... The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88233

 DenisChenu NOW ONLINE Moderator Lime Posts: 5151 Thank you received: 582 Karma: 199 benitov wrote: 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/ Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88237

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 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... The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88239

 DenisChenu NOW ONLINE Moderator Lime Posts: 5151 Thank you received: 582 Karma: 199 Hello, Review after posting, if survey date is set to dd.mm.yyyy, then: ``````AFter you can use some function like this: A new question type "no answer" with:```

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88297

 Ben_V OFFLINE Platinum Lime Posts: 869 Thank you received: 175 Karma: 60 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... The administrator has disabled public write access.

## Re: Calcul based on 2 dates 1 year 3 weeks ago #88364

 DenisChenu NOW ONLINE Moderator Lime Posts: 5151 Thank you received: 582 Karma: 199 benitov wrote: 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 Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development The administrator has disabled public write access.
 Page:12
Moderators: DenisChenu, ITEd
Time to create page: 0.218 seconds