timeDiffInMinutes( )
Calculate the time difference between two date or date/time values in minutes.
Note:
When using date type variables with no time elements, function considers time as '00:00:00'.The timeDiffInMinutes( ) helper function is invoked with toDate and fromDate passed in as parameters. The function returns a negative or positive number value indicating the difference between the two dates in minutes. If the number value returned is a negative or zero value, toDate is before or the same as fromDate. If the function returns a positive value, toDate is after fromDate.
Syntax
timeDiffInMinutes(toDate, fromDate)
Return value
Difference between the dates or date/times in minutes (number). This number can be positive or negative.
Note:
The order in which parameters are supplied for date helper functions is important; the resulting return value depends on which date you pass in as the first or second parameter.
Example 3-12 Difference between two date/time items
// Given 2 form questions of type DateTime are defined in the rule as variables:
return timeDiffInMinutes(dateTime1, dateTime2);
Example 3-13 Difference between two hard-coded date/time items
var toDate = new Date("March 1, 2020 12:02:00");
var fromDate = new Date("March 1, 2020 12:00:00");
return timeDiffInMinutes(toDate, fromDate);
// Returns value: 2
Example 3-14 Difference between 2 time items
var toDate = new Date( '01-Jan-0001 ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
var fromDate = new Date( '01-Jan-0001 ' + ruleTimeItem2.getHour() + ':' + ruleTimeItem2.getMinute() + ':' + ruleTimeItem2.getSecond() );
return timeDiffInMinutes(toDate, fromDate);
Example 3-15 Difference between two partial date items
var toDate = new Date( ruleTimeItem.getYear() + '-' + ruleTimeItem.getMonth() + '-' + ruleTimeItem.getDay() + ' ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
var fromDate = new Date( ruleTimeItem.getYear() + '-' + ruleTimeItem.getMonth() + '-' + ruleTimeItem.getDay() + ' ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
return timeDiffInMinutes(toDate, fromDate);
Parent topic: Date and time functions