# TOPIC: Calcul based on 2 dates

## Calcul based on 2 dates 3 years 2 weeks ago #88134

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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.

## Calcul based on 2 dates 3 years 2 weeks ago #88157

 DenisChenu Online Moderator Lime Posts: 7897 Thank you received: 1081 Karma: 314 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 | SkeletonQuest, RWD for LimeSurvey Last Edit: 3 years 2 weeks ago by DenisChenu. Reason: PS2 The administrator has disabled public write access.

## Calcul based on 2 dates 3 years 2 weeks ago #88160

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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.

## Calcul based on 2 dates 3 years 2 weeks ago #88168

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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: 3 years 2 weeks ago by Ben_V. The administrator has disabled public write access.

## Calcul based on 2 dates 3 years 2 weeks ago #88202

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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: ...cul.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.

## Calcul based on 2 dates 3 years 2 weeks ago #88233

 DenisChenu Online Moderator Lime Posts: 7897 Thank you received: 1081 Karma: 314 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 | SkeletonQuest, RWD for LimeSurvey The administrator has disabled public write access.

## Calcul based on 2 dates 3 years 2 weeks ago #88237

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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.

## Calcul based on 2 dates 3 years 2 weeks ago #88239

 DenisChenu Online Moderator Lime Posts: 7897 Thank you received: 1081 Karma: 314 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:```

## Calcul based on 2 dates 3 years 2 weeks ago #88297

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 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.

## Calcul based on 2 dates 3 years 2 weeks ago #88364

 DenisChenu Online Moderator Lime Posts: 7897 Thank you received: 1081 Karma: 314 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 | SkeletonQuest, RWD for LimeSurvey The administrator has disabled public write access.

## Calcul based on 2 dates 3 years 2 weeks ago #88392

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 Hi Denis, I attach the sample survey with a new approach directly based on the validation of my "ndays" variable (can't be negative value !) Maybe this is not the pefect way but do the job... (could be improved by an alert or confirm box with direct return to previous page ) What's your opinion? Attachments: ...359.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.

## Calcul based on 2 dates 3 years 1 week ago #88792

 Ben_V Offline Platinum Lime Posts: 1497 Thank you received: 355 Karma: 96 Workaround added docs.limesurvey.org/tiki-index.php?page_...ting_date_difference 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: 3 years 1 week ago by Ben_V. The administrator has disabled public write access. The following user(s) said Thank You: DenisChenu

## Calcul based on 2 dates 3 years 1 week ago #88800

 tpartner Offline LimeSurvey Team Posts: 5276 Thank you received: 1101 Karma: 458 Thanks Ben. Cheers, Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise. LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project. The administrator has disabled public write access.

## Calcul based on 2 dates 3 years 1 week ago #88839

 DenisChenu Online Moderator Lime Posts: 7897 Thank you received: 1081 Karma: 314 tpartner wrote: Thanks Ben.+1 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 | SkeletonQuest, RWD for LimeSurvey The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.213 seconds