- Posts: 9
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Calculating age at a certain date
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
10 years 10 months ago #96089
by ahchouch
Calculating age at a certain date was created by ahchouch
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!!
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 topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
10 years 10 months ago #96090
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Calculating age at a certain date
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
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
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
10 years 10 months ago - 10 years 10 months ago #96108
by ahchouch
Replied by ahchouch on topic Calculating age at a certain date
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?
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!)
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?
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!)
Attachments:
Last edit: 10 years 10 months ago by ahchouch.
The topic has been locked.
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
10 years 10 months ago #96114
by ahchouch
Replied by ahchouch on topic Calculating age at a certain date
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
Could someone help me with integrating the comparing dates script to it.
Thanks
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
10 years 10 months ago #96115
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Calculating age at a certain date
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 date s and if the returned value is negative, an alert may be displayed
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 date s and if the returned value is negative, an alert may be displayed
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
10 years 10 months ago #96116
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Calculating age at a certain date
More resource:
1) external
2) Doc (webcache google)
(search for "Calculating date difference" at the end)
3) sample survey (if you can install it...)
1) external
2) Doc (webcache google)
(search for "Calculating date difference" at the end)
3) sample survey (if you can install it...)
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
10 years 10 months ago #96182
by ahchouch
Replied by ahchouch on topic Calculating age at a certain date
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.
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.
Attachments:
The topic has been locked.
- ahchouch
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
10 years 10 months ago #96261
by ahchouch
Replied by ahchouch on topic Calculating age at a certain date
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!
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 topic has been locked.