Fix a date and time from and to in the relevant field


(Manne Munikumar) #1

How to fix a date in the relevant field like I want to select the children who born from zero days to 42 days from the date of birth and 46days to 98 days respectively. I tried (int(today() - ${dob})) >= '0' and (int(today() - ${dob})) <= '42'
(int(today() - ${dob})) >= '0' or (int(today() - ${dob})) <= '42'
i am not getting what i epected.

(Dr. Gareth S. Bestor) #2

Dates and DateTimes are represented as strings in ODK, eg "2019-01-11". So you can compare two dates to see if they are the same by using '=' or '!=' which just checks that's the two strings are identical. Similarly, because of the unique format of these strings - "YYYY-MM-DD" - you can also check the relative order of two dates using '<' or '<=', but only because it compares each string character-by-character, and the character '0' happens to be less than the character '1'... But to perform any other numerical operation on Dates and DateTImes, such as subtracting two Dates to find the number of days/months/years between them, is an operation that cannot be performed on strings. Instead, you must first convert these dates to an actual numeric representation, using the decimal-date-time(dateTime) function. eg to find the number of days between two dates:

decimal-date-time(${date1}) - decimal-date-time(${date2})

Hopefully that explains why yer not getting what you expect... :wink: Try using decimal-date-time() instead.