DateTime comparison
Compare two date questions that also contain time fields (hour and seconds), and raise a query if the dates are not as expected.
Rule description: the End Date and the Time must be on or after to the Start Date and Time in the Administration form.
Rule expression
//to meet the rule description criteria enddt-stdt should be a positive value or zero (>=0)
if(dateDiffInMinutes(enddt, stdt)>=0)
{
return true;
}
else
{
return false; //System sends query when return false condition is met
}
Query Message: The End Date and Time is before the Start Date and Time. Please correct or confirm the date(s).
Definitions
- enddt
-
Corresponds to the End Date from the rule description.
- stdt
-
Corresponds to the Start Date from the rule description.
- >=
-
Greater Than or Equal To operator. Update operator based on the rule description.
- timeDiffInMinutes( )
-
Calculates the difference between date1 (enddt), date2 (stdt) (date1-date2) in minutes.
Return value
Usage tips
Always use the relevant date helper function to compare dates rather than comparing the variables directly using comparison operators.
Verification steps
- Using a subject for testing, go to the given visit and form
containing the date items to compare, in this example the end date
<
enddt
> and start date <stdt
>. - Update the form items
enddt
andstdt
as in the following table and verify the result is as listed:enddt
stdt
Result Null
10-May-2021 11:00 AM No query 10-May-2021 11:00 AM 10-May-2021 No query 10-May-2021 11:00 AM 10-May-2021 11:01 AM Query 10-May-2021 11:00 AM 10-May-2021 10:59 AM No query 10-May-2021 11:00 AM 11-May-2021 10:59 AM Query 10-May-2021 11:00 AM 09-May-2021 10:59 AM No query 10-May-2021 11:00 AM Null
No query 12-May-2021 10-May-2021 11:00 PM Query 10-May-2021 11:05PM 10-May-2021 11:00 PM No query
Note:
Repeat the above steps if the form is present in multiple visits.
Parent topic: Date comparisons