Welcome, Guest
Username: Password: Remember me

TOPIC: Calculating age at a certain date

Calculating age at a certain date 1 year 4 months ago #96089

  • ahchouch
  • ahchouch's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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!!
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96090

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1082
  • Thank you received: 240
  • Karma: 76
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...
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96108

  • ahchouch
  • ahchouch's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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?

File Attachment:

File Name: limesurvey_group_35.lsg
File Size: 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!)
Last Edit: 1 year 4 months ago by ahchouch.
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96114

  • ahchouch
  • ahchouch's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96115

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1082
  • Thank you received: 240
  • Karma: 76
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...
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96116

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1082
  • Thank you received: 240
  • Karma: 76
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...
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96182

  • ahchouch
  • ahchouch's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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.

File Attachment:

File Name: limesurvey_group_2.lsg
File Size: 9 KB
The administrator has disabled public write access.

Calculating age at a certain date 1 year 4 months ago #96261

  • ahchouch
  • ahchouch's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.110 seconds
Donation Image