isTimeInRange( )
Verify if a date or date/time value falls within a defined range.
Syntax
Note:
When using date type variables with no time elements, function considers time as '00:00:00'.isTimeInRange(dateToCheck, dateFrom, dateTo, inclusive)
Parameters
- dateToCheck
-
Date or date/time value to check.
- dateFrom
-
Date or date/time value range start.
- dateTo
-
Date or date/time value range end.
- inclusive
-
String:
'both'
,'from'
,'to'
, or'no'
.'both'
: include dateTo and dateFrom dates in the range check (dateFrom <= dateToCheck && dateToCheck <= dateTo
)'from'
: include only dateFrom in the range check (dateFrom <= dateToCheck && dateToCheck < dateTo
)'to'
: include only dateTo in the range check (dateFrom < dateToCheck && dateToCheck <= dateTo
)'no'
: don't include dateTo or dateFrom in the range check (dateFrom < dateToCheck && dateToCheck < dateTo
)
Return value
true, if date or date/time is within range; false, if it is not.
Example 3-28 Check a date/time value
// Given 3 form questions of type DateTime are defined in the rule as variables
if (isTimeInRange(dateToCheck, dateFrom, dateTo, "both")) {
return true;
} else {
return false;
}
// Triggers query if dateToCheck is not in range (dateFrom <= dateToCheck && dateToCheck <= dateTo)
Example 3-29 Compare three hard-coded date/time items
var dateToCheck = new Date("March 1, 2020 14:00:00");
var dateFrom = new Date("March 1, 2020 12:00:00");
var dateTo = new Date("March 1, 2020 13:00:00");
if (!isTimeInRange(dateToCheck, dateFrom, dateTo, "both") {
return false;
} else {
return true;
}
//Triggers query since dateToCheck is not in range (dateFrom <= dateToCheck && dateToCheck <= dateTo)
Example 3-30 Compare two time items
var dateToCheck= new Date( '01-01-001 ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
return isTimeInRange(dateToCheck, dateFrom, dateTo, "both");
Parent topic: Date and time functions