Date subtraction is not working in a specific case

Dear All,

I am encountering a problem in my first form. Do not know what I missed. Attached two forms almost same.

This one does not show calculation results so it cannot subtract between two dates and cannot show conditional questions date_subtraction_not_work_and_do_not_show_conditional_questions.xlsx (15.8 KB)

This form shows calculation results so it can subtract between two dates and can show conditional questions.date_subtraction_works_and_show_conditional_questions.xlsx (15.4 KB)

Both forms work fine on Enketo.
Tested forms in the latest ODK collect.



I haven't tested the forms, but looking at the definitions, the only differences between the two forms are that the following variables are readonly:

For easier comparison, I'd suggest you use a consistent template.
At the moment only one of the versions has the constraint field.

I hope this helps!


round(((${visit_date}-${date_default_converted}) div 7),0)

I dont think you should be trying to directly subtract two date strings. Instead, first convert each date to number of days since epoch, subtract to find the number of days between each date, then divide number of days by 7 to find number of weeks between. eg

round((decimal-date-time(${date1}) - decimal-date-time(${date2})) div 7,0)

See decimal-date-time() for details, or have a play with this:

datediff.xls (24.5 KB)