- Posts: 1223
- Thank you received: 351
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Calculate age in an Equation type question, using Date of Birth
- Ben_V
- Offline
- Platinum Member
Less
More
11 years 6 months ago #85320
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 Calculate age in an Equation type question, using Date of Birth
Very nice solution...
Maybe the improvment could be to get it working with the 2 questions in a same group
I attach the sample survey I've created to make a try.
Thank you to share...
Ben/
Maybe the improvment could be to get it working with the 2 questions in a same group
I attach the sample survey I've created to make a try.
Thank you to share...
Ben/
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)
Attachments:
The topic has been locked.
- PawsInMotion
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
11 years 2 months ago #91050
by PawsInMotion
Replied by PawsInMotion on topic Calculate age in an Equation type question, using Date of Birth
These have all been incredibly helpful! Thank you!
Here's a trick I'm trying to figure out though (without knowing perl or much scripting at all):
How do I show year and month (and, optionally, days) from birth as chosen in the previous question.
Some of my clients aren't a year old yet (dogs) or are a year and some months.
I appreciate the help. I'll keep noodling with this code. At least I figured out that 'floor' means to round the answer.
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(365.25*24*60*60))}
Here's a trick I'm trying to figure out though (without knowing perl or much scripting at all):
How do I show year and month (and, optionally, days) from birth as chosen in the previous question.
Some of my clients aren't a year old yet (dogs) or are a year and some months.
I appreciate the help. I'll keep noodling with this code. At least I figured out that 'floor' means to round the answer.
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(365.25*24*60*60))}
The topic has been locked.
- tfj
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 20
- Thank you received: 0
11 years 2 months ago #91155
by tfj
Replied by tfj on topic Calculate age in an Equation type question, using Date of Birth
PawsInMotion:
The code I used is modular in the sense that you can substitute values in it to come up with whatever type of date measurement you need.
For instance, instead of using the following for years:
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(365.25*24*60*60))}
you can change it to:
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(24*60*60))}
for the number of days. From there, you could use Equation-type questions to come up with months and days, etc.
I tested this on a couple of cases and they seemed okay. Please let me know if your experience is different.
tfj
The code I used is modular in the sense that you can substitute values in it to come up with whatever type of date measurement you need.
For instance, instead of using the following for years:
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(365.25*24*60*60))}
you can change it to:
{floor((time() - mktime(0,0,0,substr(DateofBirth,5,2),substr(DateofBirth,8,2),substr(DateofBirth,0,4)))/(24*60*60))}
for the number of days. From there, you could use Equation-type questions to come up with months and days, etc.
I tested this on a couple of cases and they seemed okay. Please let me know if your experience is different.
tfj
The topic has been locked.
- DWS
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
10 years 8 months ago #97877
by DWS
Replied by DWS on topic Calculate age in an Equation type question, using Date of Birth
the example works fine... but if yo hide the question then you can't use the value on following questions
The topic has been locked.