Datetime constraint

Hi Kobo team,
I am having trouble with date time constraints. I used the .=today() to limit the date of data collection but it is not working for the data collectors. I am wondering if this is because the variable is a datetime not just a date? Is there a different syntax for limiting datetime values? Thank you.

Hello,
today() “Returns a string with today’s local date in the format described under the date datatype.” For example: “2021-01-08”.

But dateTime includes hours, minutes, seconds and even “the timezone offset* (i.e. not normalized to UTC). The timezone offset is HH:MM, where both hours and minutes are required and are zero-padded, preceded by the + or - sign without any spaces” (see ODK XForms Specification). For example: “2021-01-08T10:59:37.578+02:00”

So, you need to cast the dateTime variable to simple date format for the comparison, with date( … ) or the format-date-time function (ODK XForms Specification) or substr().
(But number( . ) = number( today() ) doesn’t work here. And substring-before() is not yet available.)

I add examples (tested with ODK - XLSForm Online v2.x):
DateTime01.xlsx (12.6 KB)

Also take care: Each time the form is opened the today() value will recalculate, unless ‘once’ is added (or you use the fix metadata ${today}.). See Form Logic — ODK Docs

The search function of this forum offers examples, but with date formats. See e.g. search with token “restrict to current date”:
https://community.kobotoolbox.org/t/single-response-by-surveyer-only-once-per-day/17132/2
https://community.kobotoolbox.org/t/impossible-to-insert-a-past-date-in-a-calendar/5305/4
https://community.kobotoolbox.org/t/constraining-date-in-relation-with-today-question/5174

3 Likes