Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : Calculating age at a certain date

Calculating age at a certain date il y a 1 an 6 mois #96089

  • ahchouch
  • Portrait de ahchouch
  • Hors ligne
  • Junior Lime
  • Messages : 22
  • Karma: 0
Hi Everybody
It's my first use of Limesurvey and I know nothing about Javascript!!
I have a question group including these question:
Q1: date question (dd/mm/yyyy): date of birth
Q2; date question : date of hospitalization
Q3: date question : date of intervention
I need to calculate age (in the same group) at the intervention date (DOB - DOI: in years)
I also need to verify before that:
the hospitalization date is >= to the DOB
the intervention date is >= to the hospitalization date
If one of these condition is not OK an alert should be given (according to the unsatisfied condition)and the age wouldn't be calculated than.
Please I need help!!
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96090

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 1146
  • Remerciements reçus 273
  • Karma: 79
Hello,
A part of expected responses to your questions can be found here

The topic teach how to calculate age (in an equation type question) from dob... or from any retrieved date ;)
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...
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96108

  • ahchouch
  • Portrait de ahchouch
  • Hors ligne
  • Junior Lime
  • Messages : 22
  • Karma: 0
Thanks Ben
I've alredy had a look at that and tried it. It works with today date as differential of DOB, but when I replace it with the DOI (date of intervention) it doesn't work.
I guess it has something to do with the listener :$('#answer48427X164X1612').change(function() {
I don't know if it has to be changed (and how) to listen to the change of the tow dates (DOB and DOI).
What do you think about it?
I attach the group question ( I added the second question value to the change listener!)
Could tell me what's wrong?

Fichier attaché :

Nom du fichier : limesurvey_group_35.lsg
Taille du ficher : 5 KB

To compare dates I found this:http://www.limesurvey.org/fr/forum/can-i-do-this-with-limesurvey/93224-validating-dates
Again I don't know how to combine all this to do do all the job (comparing dates and calculating age!)
Dernière édition: il y a 1 an 6 mois par ahchouch.
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96114

  • ahchouch
  • Portrait de ahchouch
  • Hors ligne
  • Junior Lime
  • Messages : 22
  • Karma: 0
It's OK. There were extra quotes (') in the listener part. Now it works fine to calculate age.
Could someone help me with integrating the comparing dates script to it.
Thanks
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96115

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 1146
  • Remerciements reçus 273
  • Karma: 79
The problem is to adapt this code to use the date at intervention instead the current date.

It looks possible and I'll make some try when I get a bit more time but if I don't start very confident because I used to face issues when manipulating dates :(

For your other questions maybe you can calculate the number of days between the 2 dates and if the returned value is negative, an alert may be displayed
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...
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96116

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 1146
  • Remerciements reçus 273
  • Karma: 79
More resource:

1) external

2) Doc (webcache google)
(search for "Calculating date difference" at the end)

3) sample survey (if you can install it...)
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...
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96182

  • ahchouch
  • Portrait de ahchouch
  • Hors ligne
  • Junior Lime
  • Messages : 22
  • Karma: 0
thank you Ben.
I actually used the script as in the attached example. For comparing dates and getting alerts, simple (if condition) were sufficiant.
here's the group with the three date questions (dob, doi, doh) and the age calculation.

Fichier attaché :

Nom du fichier : limesurvey_group_2.lsg
Taille du ficher : 9 KB
L'administrateur a désactivé l'accès en écriture pour le public.

Calculating age at a certain date il y a 1 an 6 mois #96261

  • ahchouch
  • Portrait de ahchouch
  • Hors ligne
  • Junior Lime
  • Messages : 22
  • Karma: 0
Hi
When I try to compare dates that aren't on the same page, it doesn't work.
I think it's a problem of reference to the date that isn't on the current page. I don't know how to refer to it. Seems it's not possible with JS?
How could I than calculate difference and get alerts i_n that case?
Any ideas!
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.133 secondes
Donation Image