Hi!
I am working on a form where DOB is entered in form of three integers, one integer for days, one for months, and one for year. I am aware of the “date” question types, however we need integers.
How can I calculate age in months?
I have been trying to use concat function to form yyyy-m-d from the integers and then subtracting that from today()/ div 30.24). This works very wel but only in Enketo, in doesn’t work in Kobo collect.
Any suggestions?
Caregiver test.xlsx (212.6 KB)
Hello @Kal_Lam ,
here is the extract. The row highlighted in yellow is in question. This works very well in Enketo but not in ODK/Kobocollect. I would need something that would work in Kobocollect.
Many thanks!
@pkc1 I used the info in this ODK forum post to adapt your form, it can show months in Kobocollect. You may need to use round() to not show decimals. Caregiver test.xlsx (182.0 KB)
However, you need to be careful here, because strictly speaking the correct format for dates is “YYYY-MM-DD” [see XML Schema Date/Time Datatypes]. Specifically, a month or day value that is less that 10 should be zero padded, eg 2024-04-01, which your above calculation doesn’t
So what you might be seeing is that by a mere quirk of how Enketo’s XForms engine handles date components internally that it is serendipitously not sensitive to this, whereas ODK Collect/KoboCollect’s javaRosa engine probably is.
Have you tried to see if yours works under KoboCollect when both the month and day are double-digit numbers?
BTW, aside but I also noticed this in your form:
(.>=1 and .<=31) or .= 98 and (regex(., '^[01-31]{2}$'))
FYI, in regards to your original question about calculating age in months (or days, or years for that matter), you might be interested in an article I just posted to the ODK Showcase forum showing on how to reliably calculate the correct age: Calculate age in years, months and/or days - Showcase - ODK Forum