This behavior is a little tricky, but here goes...
now() will give you a timestamp and you'll need to wrap it with once()
if you don't want the form to constantly re-evaluate it. Once you have that, you
can use format-date-time(${now_string}, '%H') to grab the hour and
format-date-time(${now_string}, '%Y') to grab the year. You then use
those in the constraints.
I've attached an example. If the behavior is not what you want, try
removing the once() part.
Yaw
datetime_constraint.xlsx (11 KB)
ยทยทยท
On Wed, Jan 18, 2017 at 9:50 AM, wrote:
> Hello, could anyone tell me whether or not it is possible to create a
> constraint in XLSForms that uses variables from the current time?
>
> For example:
>
> - User inputs a number into an integer field, but if it is more than 2 hours
> different from the current time, there is an input validation error.
> - User inputs a year into an integer field, but if it is more than 10 years
> different from the current year (2017), there is an input validation error.
>
> Thanks in advance!
>
> --
> --
> Post: opendatakit@googlegroups.com
> Unsubscribe: opendatakit+unsubscribe@googlegroups.com
> Options: http://groups.google.com/group/opendatakit?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ODK Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to opendatakit+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
1 Like