Dear Team,
I am trying to Calculate age from Date of Birth in External CSV.
Is it possible to do this.
Kindly Suggest.
Thanks.
Absolutely, calculating age from Date of Birth in an external CSV with ODK XLSForm is totally doable. Here's a quick rundown:
Make sure your CSV has a Date of Birth (DOB) column.
In your XLSForm, add a new question for the calculated age.
Use ODK's date functions to do the math. For instance, you can use "today()" to get the current date and then figure out the age based on the DOB.
Update your form logic accordingly.
Useful ODK documentation links
Building selects from CSV files
Date and time
Best of luck
1 Like
when i am trying calculation gives no response
I have pulled date of Birth from External. But when i am trying to calculate with Today() in XlS from it gives no response
Can you share the external CSV and xlsform files?
There are a lot of existing threads about this very subject, you should start with these as the problem has likely been solved unless the dates in your CSV are uniquely formatted and these approaches don't work.
I think this open issue is related to what you are trying to do.
It seems if you try and convert the string fetched through a pulldata() function into a date, the XLSForm will not validate. And to calculate the number of days you will need to be use decimal-date-time() to convert your string. See this example:
Dates are tricky.
One person did a workaround of the javarosa issue by storing the date as a number in the csv (a number that is the same value that using decimal-date-time() on the da…
Alas I'm using Kobotoolbox and it doesn't allow me to deploy.
[image]
I even tried doing format-date(string(pulldata(...))) but it doesn't work. Any other ideas?
1. What is the problem? Be very detailed.
We are working on a project which includes repeated anthropometric measures of infants across multiple time periods. We are currently developing a draft version of the form which will allow users to record these measurements. At our company we have developed a data platform system that can allow us to work with ODK forms using essentially a case management system. Therefore we will have CSV files providing information about the children and mothers for …
how to calculate age in months, days and years
I need your help I am a beginner xlsform
Hi again,
I use ODK and a I have a field date with the birthdate, and the ideai is a calculate the age, I use this formula:
format-date(today(), ‘%Y’) - format-date(${Birthdate}, ‘%Y’)
And it work, but I need to use all the date, I mean calculate the age with the year, the month and the day.
Can someone help me, please.
Calculating difference in days is possible. Use a calculate type question with the following expression:
round(decimal-date-time(today()) - decimal-date-time(${date_diagnosed}))
Calculating the number of months or years is more complicated, see this post for details:
And here's a post that explores calculating age:
2 Likes
Thanks for guide me but it is only dummy data not personal.
1 Like
To get age as number of months, try using this formula
12*(${Year1}-${Year2}) + ( ${Month1}-${Month2} )
Year1: Current Year
Month1: Current Month
Year2: DOB Year
Month2: DOB Month
Not working, if date of birth is 20/12/2023
Hi rakesh,
This formula will consider days also.
if (${Day1} < ${Day2},
12*(${Year1}-${Year2}) + (${Month1}-${Month2} - 1) + (${Day1} - ${Day2})/30,
12*(${Year1}-${Year2}) + (${Month1}-${Month2}) + (${Day1} - ${Day2})/30)