Create constraint for time (8 AM to 2 PM only allowed while collecting data)

Hello, could anyone help me to develop a constraint for a time spinner input variable? Our survey runs in particular timings 8am-2pm and surveyors have to rotate spinner to input the start time for their observation. To avoid errors in data entry, I want to limit the integers available in AM and PM slots - meaning, digits beyond 2pm and before 8am should not be available in hours slot.
Time select between 8am-2pm otherwise give error

Hello @azamiqbal,
Would you mind to share the related part of your form here, please?

Form is Attach
TIME.xlsx (9.7 KB)

Hello @azamiqual,
Maybe the following can help you to define a constraint
https://getodk.github.io/xforms-spec/#fn:decimal-time.

Hint. You depend on correct time configuration of the enumerator device. With a wrong/fake device time your constraint might be passed.

1 Like

@azamiqbal, you could follow the image below to understand on what @wroos has tried to show.

In the survey tab of your XLSForm:

Data entry screen as seen in Enketo:

Data entry screen as seen in Enketo:

Data entry screen as seen in Enketo:

Data entry screen as seen in Enketo:

Reference XLSForm:

TIME.xlsx (9.9 KB)


All you need to calculate here is the decimal-time. For this you could do as follows:

  • First, you will need to convert the time to 24 hours. This will be easy for the calculations.
  • Second, you will need to get the decimal value of 8 AM. You can do this by dividing as follows: 8 div 24. So, 8 AM in decimal value is 0.333. Similarly, you will also need to get the decimal value of 2 PM. So 2 PM in 24 hours should be 14 hours. You can get the decimal value of 14 hours by dividing as follows: 14 div 24. So, 2 PM (or 14 hours) in decimal value is 0.583. As you want to constraint till 2 PM you can use the decimal value of 0.584.

The rest if the use of if-statement, note and relevant to make it a constraint.

Thank you once again @wroos for sharing this with the community :clap: Expecting the same in the upcoming days too :heart: