- Posts: 9
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Adjusted age calculation
- Tascja
- Topic Author
- Offline
- New Member
Less
More
5 years 4 months ago #178183
by Tascja
Adjusted age calculation was created by Tascja
Hello, I'm trying to include an equation type question that calculates the adjusted age of the respondent's child. I have a question "CurrentAgeMth" that already calculated their chronological age in months (ie. today's date - child's date of birth).
I'd like to calculate their adjusted age if the child is younger than 2 years old and more than 3 weeks premature. If the child isn't premature or if the child is older than 2 years old I'd like CurrentAgeMth to display.
Q10DDate is a List(radio) question to determine if the child was premature (answer option 2).
Q10B4date is a List(radio) question to determine the number of weeks premature.
I've written the following equation but it doesn't work if the child isn't premature (line breaks added for clarity). ie. no value is shown if Q10DDate is not 2.
{if(Q10DDate !=2,CurrentAgeMth,
if((CurrentAgeMth)>24,CurrentAgeMth,
if((CurrentAgeMth)<24 AND (Q10B4date)>2, ((date("Y",(time()))-date("Y",strtotime(Q1dob)))*12+(date("m",(time()))-date("m",strtotime(Q1dob)))+((date("d",(time()))-date("d",strtotime(Q1dob)))/30)-(Q10B4date*(12/52))),CurrentAgeMth)))}
Any idea what I'm writing wrong in the equation?
Thank you all in advance for your help!
I'd like to calculate their adjusted age if the child is younger than 2 years old and more than 3 weeks premature. If the child isn't premature or if the child is older than 2 years old I'd like CurrentAgeMth to display.
Q10DDate is a List(radio) question to determine if the child was premature (answer option 2).
Q10B4date is a List(radio) question to determine the number of weeks premature.
I've written the following equation but it doesn't work if the child isn't premature (line breaks added for clarity). ie. no value is shown if Q10DDate is not 2.
{if(Q10DDate !=2,CurrentAgeMth,
if((CurrentAgeMth)>24,CurrentAgeMth,
if((CurrentAgeMth)<24 AND (Q10B4date)>2, ((date("Y",(time()))-date("Y",strtotime(Q1dob)))*12+(date("m",(time()))-date("m",strtotime(Q1dob)))+((date("d",(time()))-date("d",strtotime(Q1dob)))/30)-(Q10B4date*(12/52))),CurrentAgeMth)))}
Any idea what I'm writing wrong in the equation?
Thank you all in advance for your help!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
5 years 4 months ago #178196
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Adjusted age calculation
I think you are missing the final result (if Q10B4date) >= 2) indicated by "xx" below.
Also, you have a condition for CurrentAgeMth > 24 and CurrentAgeMth > 24b but what about CurrentAgeMth == 24 ?
Code:
{if(Q10DDate != 2 OR CurrentAgeMth > 24, CurrentAgeMth, if(CurrentAgeMth < 24 AND Q10B4date > 2, ((date("Y",(time()))-date("Y",strtotime(Q1dob)))*12+(date("m",(time()))-date("m",strtotime(Q1dob)))+((date("d",(time()))-date("d",strtotime(Q1dob)))/30)-(Q10B4date*(12/52))),CurrentAgeMth, xx))}
Also, you have a condition for CurrentAgeMth > 24 and CurrentAgeMth > 24b but what about CurrentAgeMth == 24 ?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Tascja
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
5 years 4 months ago #178252
by Tascja
Replied by Tascja on topic Adjusted age calculation
Thanks so much! I'll need to add a condition for every possible answer combination then
The topic has been locked.