Can't get Date Constraint working

Hi there,

I am having real problems with getting a constraint on someones date
of birth. I want to limit entries to within the date range of 1/1/1940
to 1/1/1996. I was trying everything I could think of, but nothing
gives me an error message. Even building a dummy form in ODK Build
failed to show any errors when I entered dates outside the range. The
dummy form is here on dpaste http://dpaste.com/613969/

I must be doing something obviously wrong, but can't work it out.....
Any help would be much appreciated!

1 Like

what we usually do is to convert the date into an approximate number
of months, then go from there. i've put an "age estimator" form at
http://pastie.org/2489394 which should help.

··· On Tue, Sep 13, 2011 at 12:37, dj_bridges wrote: > Hi there, > > I am having real problems with getting a constraint on someones date > of birth. I want to limit entries to within the date range of 1/1/1940 > to 1/1/1996. I was trying everything I could think of, but nothing > gives me an error message. Even building a dummy form in ODK Build > failed to show any errors when I entered dates outside the range. The > dummy form is here on dpaste http://dpaste.com/613969/ > > I must be doing something obviously wrong, but can't work it out..... > Any help would be much appreciated! > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

How do I restrict the to today i.e. no can should enter the date than today in my form?

I had issues with dates too, the way I ended up dealing with date issues
was to compare dates in Julian format. Not to use as constraint but to
generate various messages depending on the date range, maybe you can use a
similar methodology to get to what you need.

There is probably a better way for this, but I am performing a
mathematical operation on a date variable, so it returns the Julian date,
and comparing that with my known dates in Julian format, eg. comparing
now()-1 with my desired dates.

··· On 13/09/11 11:37 PM, "Yaw Anokwa" wrote:

what we usually do is to convert the date into an approximate number
of months, then go from there. i've put an "age estimator" form at
http://pastie.org/2489394 which should help.

On Tue, Sep 13, 2011 at 12:37, dj_bridges danieljbridges@gmail.com wrote:

Hi there,

I am having real problems with getting a constraint on someones date
of birth. I want to limit entries to within the date range of 1/1/1940
to 1/1/1996. I was trying everything I could think of, but nothing
gives me an error message. Even building a dummy form in ODK Build
failed to show any errors when I entered dates outside the range. The
dummy form is here on dpaste http://dpaste.com/613969/

I must be doing something obviously wrong, but can't work it out.....
Any help would be much appreciated!

--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en

--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en

Hi there,

If you want future dates, use a constraint of ". >= today()". If you
want dates before today, use a constraint of ". <= today()". If you
match to today, use ". = today()".

Note that today() is based on the date and time of the device. That
date and time can be changed by the user or the cell provider, so it
might not actually be correct.

Yaw

··· On Tue, Sep 20, 2016 at 7:41 AM, wrote: > How do I restrict the to today i.e. no can should enter the date than today in my form? > > -- > -- > 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.

Thanks for the replies - very helpful. Pooya - any chance you could
post a form on dpaste or pastie to show me what you do?

I now see how I can do the calculations to work out someones age in a
number of sequential questions. However this is only really useful if
I can get a constraintmsg to pop up if a date entered falls outside
the required range. To my mind, the easiest way to achieve this would
be to perform the calculation within the constraint - is this
possible?

Am guessing that this is a common requirement for a lot of people
building forms so there must be a solution out there. Or is it simply
not possible to enter a date and constrain it to a date range within
that question? If so then I would suggest that you remove this
functionality from ODK Build, which allows one to apply date
constraints, but as I have found out, it doesn't work....

you cannot do the entire evaluation in one widget (because you have to
ask for age in years/months, etc), but in the example i showed, you
should be able to put the check for approximate age in a constraint
(say for the output age prompt, don't go forward unless approximate
age >= 216 months). whew. that's a long sentence.

i agree that date constraints of one sort or another are a good
feature. i need to look into the core to see what options we have and
we'll implement them in build as time allows. i've filed the bug at
http://code.google.com/p/opendatakit/issues/detail?id=323 for now.

··· On Wed, Sep 14, 2011 at 09:42, dj_bridges wrote: > Thanks for the replies - very helpful. Pooya - any chance you could > post a form on dpaste or pastie to show me what you do? > > I now see how I can do the calculations to work out someones age in a > number of sequential questions. However this is only really useful if > I can get a constraintmsg to pop up if a date entered falls outside > the required range. To my mind, the easiest way to achieve this would > be to perform the calculation within the constraint - is this > possible? > > Am guessing that this is a common requirement for a lot of people > building forms so there must be a solution out there. Or is it simply > not possible to enter a date and constrain it to a date range within > that question? If so then I would suggest that you remove this > functionality from ODK Build, which allows one to apply date > constraints, but as I have found out, it doesn't work.... > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

haven't tested this yet, but the following should work (thanks to drew
from dimagi!)

constraint="date(.) >= date('2005-01-01') and date(.) <=
date('2007-12-31')"

when we can add this to build, i dunno, but the bug has been filed and
this solution should work for now. please follow up on the bug if it
doesn't work.

http://code.google.com/p/opendatakit/issues/detail?id=323

··· On Fri, Sep 16, 2011 at 17:32, Yaw Anokwa wrote: > you cannot do the entire evaluation in one widget (because you have to > ask for age in years/months, etc), but in the example i showed, you > should be able to put the check for approximate age in a constraint > (say for the output age prompt, don't go forward unless approximate > age >= 216 months). whew. that's a long sentence. > > i agree that date constraints of one sort or another are a good > feature. i need to look into the core to see what options we have and > we'll implement them in build as time allows. i've filed the bug at > http://code.google.com/p/opendatakit/issues/detail?id=323 for now. > > On Wed, Sep 14, 2011 at 09:42, dj_bridges wrote: >> Thanks for the replies - very helpful. Pooya - any chance you could >> post a form on dpaste or pastie to show me what you do? >> >> I now see how I can do the calculations to work out someones age in a >> number of sequential questions. However this is only really useful if >> I can get a constraintmsg to pop up if a date entered falls outside >> the required range. To my mind, the easiest way to achieve this would >> be to perform the calculation within the constraint - is this >> possible? >> >> Am guessing that this is a common requirement for a lot of people >> building forms so there must be a solution out there. Or is it simply >> not possible to enter a date and constrain it to a date range within >> that question? If so then I would suggest that you remove this >> functionality from ODK Build, which allows one to apply date >> constraints, but as I have found out, it doesn't work.... >> >> -- >> Post: opendatakit@googlegroups.com >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en >> >
1 Like

Works perfectly - thank you Yaw and Drew!

Thanks for this awesome feedback and for your work in general, Yaw and team :slight_smile:

In terms of applying constraint codes in xls spreadsheets, I placed the following constraint for an upcoming survey to be delivered this year and next:

.>=date(2016-08-01) and .<=date(2017-12-31)

and also

.>=(date(2016-08-01)) and .<=(date(2017-12-31))

Unfortunately, any date between the range of 16/8/1 - 17/12/31 that is input in the enketo field is flagged as an error. Any suggestions?

Many thanks,
Marcel
Task Force for Global Health

··· On Friday, September 16, 2011 at 10:59:19 AM UTC-4, Yaw Anokwa wrote: > haven't tested this yet, but the following should work (thanks to drew > from dimagi!) > > constraint="date(.) >= date('2005-01-01') and date(.) <= > date('2007-12-31')" > > when we can add this to build, i dunno, but the bug has been filed and > this solution should work for now. please follow up on the bug if it > doesn't work. > > http://code.google.com/p/opendatakit/issues/detail?id=323 > > > On Fri, Sep 16, 2011 at 17:32, Yaw Anokwa wrote: > > you cannot do the entire evaluation in one widget (because you have to > > ask for age in years/months, etc), but in the example i showed, you > > should be able to put the check for approximate age in a constraint > > (say for the output age prompt, don't go forward unless approximate > > age >= 216 months). whew. that's a long sentence. > > > > i agree that date constraints of one sort or another are a good > > feature. i need to look into the core to see what options we have and > > we'll implement them in build as time allows. i've filed the bug at > > http://code.google.com/p/opendatakit/issues/detail?id=323 for now. > > > > On Wed, Sep 14, 2011 at 09:42, dj_bridges wrote: > >> Thanks for the replies - very helpful. Pooya - any chance you could > >> post a form on dpaste or pastie to show me what you do? > >> > >> I now see how I can do the calculations to work out someones age in a > >> number of sequential questions. However this is only really useful if > >> I can get a constraintmsg to pop up if a date entered falls outside > >> the required range. To my mind, the easiest way to achieve this would > >> be to perform the calculation within the constraint - is this > >> possible? > >> > >> Am guessing that this is a common requirement for a lot of people > >> building forms so there must be a solution out there. Or is it simply > >> not possible to enter a date and constrain it to a date range within > >> that question? If so then I would suggest that you remove this > >> functionality from ODK Build, which allows one to apply date > >> constraints, but as I have found out, it doesn't work.... > >> > >> -- > >> Post: opendatakit@googlegroups.com > >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com > >> Options: http://groups.google.com/group/opendatakit?hl=en > >> > >

Hi Marcel,

If it's an issue with Enketo, please check with the Enketo team.

Yaw

··· -- Need ODK consultants? Nafundi provides form design, server setup, in-field training, and software development for ODK. Go to https://nafundi.com to get started.

On Tue, Aug 2, 2016 at 2:07 PM, mfoster@taskforce.org wrote:

Thanks for this awesome feedback and for your work in general, Yaw and team :slight_smile:

In terms of applying constraint codes in xls spreadsheets, I placed the following constraint for an upcoming survey to be delivered this year and next:

.>=date(2016-08-01) and .<=date(2017-12-31)

and also

.>=(date(2016-08-01)) and .<=(date(2017-12-31))

Unfortunately, any date between the range of 16/8/1 - 17/12/31 that is input in the enketo field is flagged as an error. Any suggestions?

Many thanks,
Marcel
Task Force for Global Health

On Friday, September 16, 2011 at 10:59:19 AM UTC-4, Yaw Anokwa wrote:

haven't tested this yet, but the following should work (thanks to drew
from dimagi!)

constraint="date(.) >= date('2005-01-01') and date(.) <=
date('2007-12-31')"

when we can add this to build, i dunno, but the bug has been filed and
this solution should work for now. please follow up on the bug if it
doesn't work.

http://code.google.com/p/opendatakit/issues/detail?id=323

On Fri, Sep 16, 2011 at 17:32, Yaw Anokwa yanokwa@gmail.com wrote:

you cannot do the entire evaluation in one widget (because you have to
ask for age in years/months, etc), but in the example i showed, you
should be able to put the check for approximate age in a constraint
(say for the output age prompt, don't go forward unless approximate
age >= 216 months). whew. that's a long sentence.

i agree that date constraints of one sort or another are a good
feature. i need to look into the core to see what options we have and
we'll implement them in build as time allows. i've filed the bug at
http://code.google.com/p/opendatakit/issues/detail?id=323 for now.

On Wed, Sep 14, 2011 at 09:42, dj_bridges danieljbridges@gmail.com wrote:

Thanks for the replies - very helpful. Pooya - any chance you could
post a form on dpaste or pastie to show me what you do?

I now see how I can do the calculations to work out someones age in a
number of sequential questions. However this is only really useful if
I can get a constraintmsg to pop up if a date entered falls outside
the required range. To my mind, the easiest way to achieve this would
be to perform the calculation within the constraint - is this
possible?

Am guessing that this is a common requirement for a lot of people
building forms so there must be a solution out there. Or is it simply
not possible to enter a date and constrain it to a date range within
that question? If so then I would suggest that you remove this
functionality from ODK Build, which allows one to apply date
constraints, but as I have found out, it doesn't work....

--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en

--

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.

Thanks so much Yaw. Please let me clarify. The issue is not with Enketo.
The issue is that the following constraint string, which I extrapolated
from your posts:

.>=date(2016-08-01) and .<=date(2017-12-31)

is not working in terms of only allowing dates to be entered between August
1, 2016 and December 31st, 2017. This is also consistent in other tests
that we practice when generating the xlm forms. Any insights you have on
making this constraint work for the date range would be extremely
appreciated.

Thanks so much again,
Marcel

··· On Wed, Aug 3, 2016 at 5:02 AM, Yaw Anokwa wrote:

Hi Marcel,

If it's an issue with Enketo, please check with the Enketo team.

Yaw

Need ODK consultants? Nafundi provides form design, server setup,
in-field training, and software development for ODK. Go to
https://nafundi.com to get started.

On Tue, Aug 2, 2016 at 2:07 PM, mfoster@taskforce.org wrote:

Thanks for this awesome feedback and for your work in general, Yaw and
team :slight_smile:

In terms of applying constraint codes in xls spreadsheets, I placed the
following constraint for an upcoming survey to be delivered this year and
next:

.>=date(2016-08-01) and .<=date(2017-12-31)

and also

.>=(date(2016-08-01)) and .<=(date(2017-12-31))

Unfortunately, any date between the range of 16/8/1 - 17/12/31 that is
input in the enketo field is flagged as an error. Any suggestions?

Many thanks,
Marcel
Task Force for Global Health

On Friday, September 16, 2011 at 10:59:19 AM UTC-4, Yaw Anokwa wrote:

haven't tested this yet, but the following should work (thanks to drew
from dimagi!)

constraint="date(.) >= date('2005-01-01') and date(.) <=
date('2007-12-31')"

when we can add this to build, i dunno, but the bug has been filed and
this solution should work for now. please follow up on the bug if it
doesn't work.

http://code.google.com/p/opendatakit/issues/detail?id=323

On Fri, Sep 16, 2011 at 17:32, Yaw Anokwa yanokwa@gmail.com wrote:

you cannot do the entire evaluation in one widget (because you have to
ask for age in years/months, etc), but in the example i showed, you
should be able to put the check for approximate age in a constraint
(say for the output age prompt, don't go forward unless approximate
age >= 216 months). whew. that's a long sentence.

i agree that date constraints of one sort or another are a good
feature. i need to look into the core to see what options we have and
we'll implement them in build as time allows. i've filed the bug at
http://code.google.com/p/opendatakit/issues/detail?id=323 for now.

On Wed, Sep 14, 2011 at 09:42, dj_bridges danieljbridges@gmail.com wrote:

Thanks for the replies - very helpful. Pooya - any chance you could
post a form on dpaste or pastie to show me what you do?

I now see how I can do the calculations to work out someones age in a
number of sequential questions. However this is only really useful if
I can get a constraintmsg to pop up if a date entered falls outside
the required range. To my mind, the easiest way to achieve this would
be to perform the calculation within the constraint - is this
possible?

Am guessing that this is a common requirement for a lot of people
building forms so there must be a solution out there. Or is it simply
not possible to enter a date and constrain it to a date range within
that question? If so then I would suggest that you remove this
functionality from ODK Build, which allows one to apply date
constraints, but as I have found out, it doesn't work....

--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en

--

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.

--

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 a topic in the
Google Groups "ODK Community" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/opendatakit/xtB1STXa1Ck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

See https://opendatakit.org/help/form-design/binding/

date('2011-11-12')

i.e., with quotes and in a different format

is the correct syntax.

··· On Wed, Aug 3, 2016 at 6:31 AM, Marcel Foster (Intern) < mfoster@taskforce.org> wrote:

Thanks so much Yaw. Please let me clarify. The issue is not with Enketo.
The issue is that the following constraint string, which I extrapolated
from your posts:

.>=date(2016-08-01) and .<=date(2017-12-31)

is not working in terms of only allowing dates to be entered between
August 1, 2016 and December 31st, 2017. This is also consistent in other
tests that we practice when generating the xlm forms. Any insights you have
on making this constraint work for the date range would be extremely
appreciated.

Thanks so much again,
Marcel

On Wed, Aug 3, 2016 at 5:02 AM, Yaw Anokwa yanokwa@nafundi.com wrote:

Hi Marcel,

If it's an issue with Enketo, please check with the Enketo team.

Yaw

Need ODK consultants? Nafundi provides form design, server setup,
in-field training, and software development for ODK. Go to
https://nafundi.com to get started.

On Tue, Aug 2, 2016 at 2:07 PM, mfoster@taskforce.org wrote:

Thanks for this awesome feedback and for your work in general, Yaw and
team :slight_smile:

In terms of applying constraint codes in xls spreadsheets, I placed the
following constraint for an upcoming survey to be delivered this year and
next:

.>=date(2016-08-01) and .<=date(2017-12-31)

and also

.>=(date(2016-08-01)) and .<=(date(2017-12-31))

Unfortunately, any date between the range of 16/8/1 - 17/12/31 that is
input in the enketo field is flagged as an error. Any suggestions?

Many thanks,
Marcel
Task Force for Global Health

On Friday, September 16, 2011 at 10:59:19 AM UTC-4, Yaw Anokwa wrote:

haven't tested this yet, but the following should work (thanks to drew
from dimagi!)

constraint="date(.) >= date('2005-01-01') and date(.) <=
date('2007-12-31')"

when we can add this to build, i dunno, but the bug has been filed and
this solution should work for now. please follow up on the bug if it
doesn't work.

http://code.google.com/p/opendatakit/issues/detail?id=323

On Fri, Sep 16, 2011 at 17:32, Yaw Anokwa yanokwa@gmail.com wrote:

you cannot do the entire evaluation in one widget (because you have
to
ask for age in years/months, etc), but in the example i showed, you
should be able to put the check for approximate age in a constraint
(say for the output age prompt, don't go forward unless approximate
age >= 216 months). whew. that's a long sentence.

i agree that date constraints of one sort or another are a good
feature. i need to look into the core to see what options we have and
we'll implement them in build as time allows. i've filed the bug at
http://code.google.com/p/opendatakit/issues/detail?id=323 for now.

On Wed, Sep 14, 2011 at 09:42, dj_bridges danieljbridges@gmail.com wrote:

Thanks for the replies - very helpful. Pooya - any chance you could
post a form on dpaste or pastie to show me what you do?

I now see how I can do the calculations to work out someones age in
a
number of sequential questions. However this is only really useful
if
I can get a constraintmsg to pop up if a date entered falls outside
the required range. To my mind, the easiest way to achieve this
would
be to perform the calculation within the constraint - is this
possible?

Am guessing that this is a common requirement for a lot of people
building forms so there must be a solution out there. Or is it
simply
not possible to enter a date and constrain it to a date range within
that question? If so then I would suggest that you remove this
functionality from ODK Build, which allows one to apply date
constraints, but as I have found out, it doesn't work....

--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en

--

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.

--

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 a topic in the
Google Groups "ODK Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/opendatakit/xtB1STXa1Ck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Sorry for the thread-rez... but I really think this should be in the documentation... really hard to find out this winning syntax!

That's a reasonable idea. Where in the docs would you expect to see it?

Perhaps here:
http://xlsform.org/en/#constraints That's the first place I looked since it's the formal documentation.

Or?

FYI, I believe in XPath2 you can compare strings, and due to the particular formatting of dates (YYYY-MM-DD) the following should also work:

(. >= '2005-01-01') and (. <= '2007-12-31')

but arguably explicitly converting (both) the date strings is 'safer' [eg the above wont work under XPath1]

1 Like

Dear Marcel,

You can use this command following command in constraint column for date it work.

(. >= date('2016-08-01')) and (. <= date('2017-12-31'))

Try this command.

Thanks & regards,

Anil