Auto generating age in years and months from Date of Birth

This is Dynamite!

Steven, we’re always very impressed by your work, I wonder if you might like to post something about the use and methods of the Calculate function?
☞§※☼:airplane::open_umbrella::slight_smile:

~Neil

···

On Wed, May 8, 2013 at 8:05 AM, Collins McAdoyo collin...@gmail.com wrote:

Hi Team members, I was creating a survey with Variables Date of Birth and Age. Is it possible to autogenarate Age in Years and Months from the date of birth entered?

Q3. Enter date of birth (dd/mm/yyyy): //_________

Q5. Current Age: Years:________________ Months:____________

Thanks

Collins


You received this message because you are subscribed to the Google Groups “Kobo Users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to kobo-users+...@googlegroups.com.

To post to this group, send email to kobo-...@googlegroups.com.
Visit this group at http://groups.google.com/group/kobo-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

+254721260024

Aloo Stephen Onuong’a
Public Health & Social Research Specialist

Hello Neil

Will do so… I am currently working on a tool that is taking your KOBO to the greatest test limits so I will be able to document a lot based on this assignment with calculate function among other functions that I found could work with the sytem. So probably at a later stage. Thanks for the complement. On a lighter note since last year we are now implementing national level Study Number 11 using KOBO (teams have nicknamed the phones KOBO and call each other Koblets)

Aloo Stephen Onuong’a

···

On Wed, May 8, 2013 at 8:05 AM, Collins McAdoyo collin...@gmail.com wrote:

Hi Team members, I was creating a survey with Variables Date of Birth and Age. Is it possible to autogenarate Age in Years and Months from the date of birth entered?

Q3. Enter date of birth (dd/mm/yyyy): //_________

Q5. Current Age: Years:________________ Months:____________

Thanks

Collins


You received this message because you are subscribed to the Google Groups “Kobo Users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to kobo-users+...@googlegroups.com.

To post to this group, send email to kobo-...@googlegroups.com.
Visit this group at http://groups.google.com/group/kobo-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

+254721260024

Aloo Stephen Onuong’a
Public Health & Social Research Specialist

Fantastic! Do please let us know more about your study, I’ll add something to the user showcases for you. We often call eachother “KoBoNauts”

☞§※☼:airplane::open_umbrella::slight_smile:

~Neil

···

On Wed, May 8, 2013 at 8:05 AM, Collins McAdoyo collin...@gmail.com wrote:

Hi Team members, I was creating a survey with Variables Date of Birth and Age. Is it possible to autogenarate Age in Years and Months from the date of birth entered?

Q3. Enter date of birth (dd/mm/yyyy): //_________

Q5. Current Age: Years:________________ Months:____________

Thanks

Collins


You received this message because you are subscribed to the Google Groups “Kobo Users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to kobo-users+...@googlegroups.com.

To post to this group, send email to kobo-...@googlegroups.com.
Visit this group at http://groups.google.com/group/kobo-users?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

+254721260024

Aloo Stephen Onuong’a
Public Health & Social Research Specialist

Hi
I need to make the phone number be eleven digits not increase not decrease

Hi you can use this in constraints field:
regex(.,’[0-9]{11}’)

@moteb_marei Please see my recent posting Number constraints - #6 by Xiphware as to why this regex is incorrect.

@ziyad Could you please remember to open a new thread topic for new questions, this is rather unrelated to the original topic. Or if you want to email another forum member directly you can use the Flag control to send them a private message.

Hi,

But if you make the type of question integer nobody will be able to write string entries

Best Regards

Moteb Marei

Please note that using an integer question to enter phone numbers is problematic due to the limited number of digits allowed (max 9), which may well be insufficient to store a long phone number. It is therefore recommended - for phone numbers - to use a regular text widget (which effectively has unlimited length) with an appearance=“numbers”. But this is basically only a hint to the XForm client to display a keyboard that only permits entering numbers, which depending on your platform may or may not be possible (eg Enketo cant control your laptops keyboard…). So in addition it is also recommended to add a suitable constraint regex (see above) to ensure that the user only submits numbers.

if still suffering from that can you try this:
regex (.,’^[A-Za-z0-9._؟?#&*/@;:؛÷×%$ ±]
{11} $’)

Good grief! What ARE you trying to match!?! :slight_smile:

But seriously, what sort of user input data are you trying to validate, and in what way is your regex above misbehaving? Perhaps give a couple of example of strings that you want to match, and I’m sure we can come up with a suitable regex.

Sorry I didn’t understand what you meant exactly:
But in my work we are using ID entering for beneficiaries to avoid duplicating in names … to match assessment data with distribution data:
ID number is unique for all citizens and consists from 11 numbers… so in above regex i force enumerators to add only number with “text” type of question… we have 2 languages Arabic and English… Some times they are laptops to fill data into server

Unfortunately, multi-lingual regexs are beyond my scope of expertise (I don’t even know if you can do them). Perhaps someone else here who has successfully implemented constraint checking against non-English text input can provide some insight?

Yes Dear we are using Arabic Language mainly but the form in English as you know, So to prevent people making mistake I did that regex.

Dear @stephanealoo,

I have the exact same question as asked by @Collins. I am having a hard time in understanding your code - where do I paste it in my Excel form?

I have two date variables : 1) date of survey and 2) date of birth

Would really appreciate if you could help me understand this.

Thanking in anticipation.

Hi @mahrukhkhan

That was such a long time. There is now an article that clearly describes how to do advanced calculation. Kindly check on it here and if you don’t find your solution, please type your question and example so that we can chime in on it.

Regards
Stephane

1 Like

Hi @stephanealoo,

Actually my question is not just about the calculation of dates. It is about the display of the calculation in Years, Months.

I have a date variable which opens up the calendar to enter date of survey.
I have another date variable which opens up the calendar to enter the date of birth.

I then calculate the age by subtracting the date of birth from the date of survey. In my data set, if the child is 15 months old, the age displayed is “15 months”. However, I want the display to be “1 year 3 months”.

Is it possible to do this on Kobo?

Please let me know if there is a solution to this.

Hi
I created a form just to explain this find it attached hereCalculateExamples.xls (26 KB)

Focus on the area shown below

Your output should be something like this

And as indicated by @Xiphware FYI depending on how pedantic you wish to be, you might be interested in this thread (specifically discussing leap years…). But since you just want years and months here - that is, the precise number of days doesn’t matter - the impact of leap years will be nominal.
Regards
Stephane

2 Likes

That worked. Thank you so much @stephanealoo! Really appreciate your effort.

2 Likes

FYI depending on how pedantic you wish to be, you might be interested in this thread (specifically discussing leap years…). But since you just want years and months here - that is, the precise number of days doesn’t matter - the impact of leap years will be nominal.

2 Likes

Hi @Xiphware,

Thanks for the link. This is super useful!

1 Like