1. What is the issue?.
Hi,
I am trying to calculate the year difference from today's date and date pulled from external csv file. while checking the form on Enketo it can calculate easily. but on mobile using ODK collect app it says the value "1-apr-1990" (for say) can't be converted into a date.
2. What have you tried to fix the issue?
I have converted the date formats into Gregorian Calendar in the CSV file and also tried with many other formats but no success.
I have also checked that calculating the days difference from manually entered dates works fine on both Enketo and ODK collect android app.
Do anyone knows what is the issue and how to resolve it?
Test forms and external file is attached herewith Book1.xlsx (14.4 KB) demo.csv (42 Bytes)
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 date string would give). So in your CSV you would add a column with a formula such as =(A3-DATE(1970,1,1)) playing_with_dates.xlsx (10.3 KB) and demo.csv (74 Bytes)
However, because of time of day, there are some oddities that emerge. For example when considering the time of day. Note the slight difference in number of days difference below.
To calculate the number of whole years, such as the age of a person, using the div 365.25 technique can sometimes error if the month and day of month are close. As noted in the first post I linked:
Note that I posted an exploration of that here with what (I think) should be an alternate way to calculate it: