Is it possible to validate dates in odk-x

For example the birthdate should not precede lets say date of registration or date of registration should not be a future date or date of birth should not be a future date

1 Like

Hi @hissdev! Yes, this is entirely possible using the constraint column in the survey. Starting on line 88 in 1_0_statistical_identification of the attached, we assign the “today” date. Then in line 90 we constrain the date to be today (or earlier) (see constraint column and the messages that are displayed in display.constraint_message.text). You can use a similar syntax for any two sets of dates. quest1_00_0_ELMPS.xlsx (461.7 KB)

1 Like

Many many thanks @elmps2018
I have succeeded partially. The today’s date is displayed but the other date is in another date format, so I can’t move to the next.

Attached are the images

You may need to make these the same format, which should be doable for either of them to change. You can also check the table to see if they are being recorded differently. If you’re still having trouble you can share the excel so we can take a look.

Many thanks @elmps2018
I have checked and rechecked the dates are of different formats. The example on start_today is a string and when I change the format to date the date today’s changes to November 2020 date .Am still confused because changing the dates to same format alters everything and does not allow me to proceed. Again more guidance will be appreciated

For a date earlier than today you can use data(‘variable’) <= now() as the constraint with whatever date variable you are trying to constrain, that’s one of the ways we do it in the file I shared.

Alternatively, if your date is recording a different order then you may need to construct today in a different order. You can look at what gets recorded in tables to see and update the today ((now().getYear()+1900)+’-’+(now().getMonth()+1)+’-’+(now().getDate())) accordingly.

1 Like