Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

caluculate age in months

More
11 years 9 months ago #115904 by first
Hi, Need help!!..

I have date question with mm dd yyyy format in which respondent enter date of birth. I need to caluculate age in months ..

Thanks
Trivender

Survey Designer and Programmer
The topic has been locked.
More
11 years 9 months ago #115916 by DenisChenu
Replied by DenisChenu on topic caluculate age in months
Something like:
{(date("YY",strtotime(BIRTH)-date("YY"))*12 + (date("m",strtotime(BIRTH)-date("m"))}

Not tested

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: first
The topic has been locked.
More
11 years 9 months ago #116013 by first
Replied by first on topic caluculate age in months
Thanks Denis, But it didnt worked for me. I tried some javascript and it worked.
Code:
<script> var dob = '{q1}'.split(' ')[0]; //q1 is date question. var dobarr = dob.split('-'); var dobY = Number(dobarr[0]); var dobM = Number(dobarr[1]); var dobD = Number(dobarr[2]); var nowarr = '{date('Y-m-d')}'.split('-'); var nowY = Number(nowarr[0]); var nowM = Number(nowarr[1]); var nowD = Number(nowarr[2]); var months = ((nowY - dobY)*12) + (nowM-dobM) + Number(((nowD-dobD)/30).toFixed(2)); //set months in your open end question using javascript </script>

Survey Designer and Programmer
The topic has been locked.
Moderators: holch, tpartner

Lime-years ahead

Online-surveys for every purse and purpose