Validation condition for current time


(Ameera Hamid) #1

Hi everyone,

I am creating an electronic logbook using the commcare platform for my
first year clinical students. one of the forms created is a clock-in form
when they arrive at their clinical site. i have added a time question to
the form and would like to add a validation so that the time entered cannot
be later than the current time or later than 8.30 am. how would the
expression look like in the xpression builder?

Kind regards,
Ameera


(William Pride) #2

Hi Ameera,

So if I’m understanding correctly you want to enforce that the time entered
is earlier than the current time AND earlier than 8:30 am? If so, I’d
recommend looking at the following two pages:

https://confluence.dimagi.com/display/commcarepublic/Common+Logic+and+Calculations
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-format-date

In the first link, under the “validation” section you should find some
useful information about how to enforce that the time is earlier. In the
second link under the “format-date” section you should find some useful
information about how to pull out the required hour and minute values so
that you can use the less-than operator to enforce a range on these
numbers. If you concatenate the two together you will end up with the
desired validation condition.

Best,
Will

··· On Tue, Feb 25, 2014 at 3:52 AM, Ameera Hamid wrote:

Hi everyone,

I am creating an electronic logbook using the commcare platform for my
first year clinical students. one of the forms created is a clock-in form
when they arrive at their clinical site. i have added a time question to
the form and would like to add a validation so that the time entered cannot
be later than the current time or later than 8.30 am. how would the
expression look like in the xpression builder?

Kind regards,
Ameera


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Ameera Hamid) #3

HI Will,

Thanks for your suggestion. How could i set the validation so that the
time entered is equal to the current time. for example, the validation for
entering only todays days date is .=today() what is the equivalent
validatio for time?

-Ameera :slight_smile:

··· On Tuesday, 25 February 2014 19:09:27 UTC+2, William Pride wrote: > > Hi Ameera, > > So if I'm understanding correctly you want to enforce that the time > entered is earlier than the current time AND earlier than 8:30 am? If so, > I'd recommend looking at the following two pages: > > > https://confluence.dimagi.com/display/commcarepublic/Common+Logic+and+Calculations > > https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-format-date > > In the first link, under the "validation" section you should find some > useful information about how to enforce that the time is earlier. In the > second link under the "format-date" section you should find some useful > information about how to pull out the required hour and minute values so > that you can use the less-than operator to enforce a range on these > numbers. If you concatenate the two together you will end up with the > desired validation condition. > > Best, > Will > > > On Tue, Feb 25, 2014 at 3:52 AM, Ameera Hamid <ameera....@gmail.com wrote: > >> Hi everyone, >> >> I am creating an electronic logbook using the commcare platform for my >> first year clinical students. one of the forms created is a clock-in form >> when they arrive at their clinical site. i have added a time question to >> the form and would like to add a validation so that the time entered cannot >> be later than the current time or later than 8.30 am. how would the >> expression look like in the xpression builder? >> >> Kind regards, >> Ameera >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/groups/opt_out. >> > >

(Clayton Sims) #4

Ameera,

Validation conditions have to be valid for the entirety of form entry, so
forcing the user to set the value to the exact current time might be
frustrating (if it takes more than a minute to enter the form you’ll have
to go update it again. You may find it easier to simply set the current
date and time with a “hidden value” in your form, which allows you to set a
calculated condition that the user doesn’t have to input themselves.

In fact, the Start date/time and end date/time of every form is
automatically set, so if you only need the data for analysis purposes
(don’t need to display it to the user) you won’t need to configure anything
at all. It will just show up automatically in form exports.

-Clayton

··· On Thu, Feb 27, 2014 at 6:11 AM, Ameera Hamid wrote:

HI Will,

Thanks for your suggestion. How could i set the validation so that the
time entered is equal to the current time. for example, the validation for
entering only todays days date is .=today() what is the equivalent
validatio for time?

-Ameera :slight_smile:

On Tuesday, 25 February 2014 19:09:27 UTC+2, William Pride wrote:

Hi Ameera,

So if I’m understanding correctly you want to enforce that the time
entered is earlier than the current time AND earlier than 8:30 am? If so,
I’d recommend looking at the following two pages:

https://confluence.dimagi.com/display/commcarepublic/Common+
Logic+and+Calculations
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#
CommCareFunctions-format-date

In the first link, under the “validation” section you should find some
useful information about how to enforce that the time is earlier. In the
second link under the “format-date” section you should find some useful
information about how to pull out the required hour and minute values so
that you can use the less-than operator to enforce a range on these
numbers. If you concatenate the two together you will end up with the
desired validation condition.

Best,
Will

On Tue, Feb 25, 2014 at 3:52 AM, Ameera Hamid ameera....@gmail.comwrote:

Hi everyone,

I am creating an electronic logbook using the commcare platform for my
first year clinical students. one of the forms created is a clock-in form
when they arrive at their clinical site. i have added a time question to
the form and would like to add a validation so that the time entered cannot
be later than the current time or later than 8.30 am. how would the
expression look like in the xpression builder?

Kind regards,
Ameera


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Peggy Wanza) #5

Hi Clayton,
But what would the validation condition look like?
I have two time variables and I want to set it such that the second time must be greater than the first.

Am sure I’ll need the validation condition for this.

Kindly assist.


(Cody Stahl) #6

Hi Peggy,

To compare two Time questions, you will need to convert the time string into an integer representing the number of minutes since midnight. To do this, you would use the calculation:

substr(#form/time_question,0,2) * 60 + substr(#form/time_question,3,5)

(You could go further into seconds and milliseconds, but for most use cases this won’t be necessary).

If you have a question time_question_1, and you want a validation condition on time_question_2 that it needs to be later then time_question_1, that validation condition could look like this:

substr(.,0,2) * 60 + substr(.,3,5) > substr(#form/time_question_1,0,2) * 60 + substr(#form/time_question_1,3,5)

For more information, please see our help page on Calculations with Dates and Times.