timeDiffInSeconds( )
Calculate the time difference between two date or date/time values in seconds.
The timeDiffInSeconds( ) helper function is invoked with starting and ending dates passed in as parameters. The function returns a negative or positive number value indicating the difference between the two dates in seconds.
When using date type variables with no time elements, function considers time as '00:00:00'.
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.This rule helper function is approved for use in Screen Candidate rule execution.
Syntax
timeDiffInSeconds(toDate, fromDate)Parameters
| Parameter | Required or Optional | Description |
|---|---|---|
toDate |
Required | Ending date value. |
fromDate |
Required | Starting date value. |
Return value
Number that represents the difference between the passed-in dates in seconds.
This number can be positive or negative.
- If the number value returned is a negative or zero value, means that
toDateis before or the same as thefromDate. - If the function returns a positive value,
toDateis after thefromDate.
Examples
Example 3-17 Difference between two date/time items
// Given 2 form questions of type DateTime are defined in the rule as variables:
return timeDiffInSeconds(dateTime1, dateTime2);Example 3-18 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 timeDiffInSeconds(toDate, fromDate);
// Returns value: 120Example 3-19 Difference between two time items
var date1 = new Date( '01-Jan-0001 ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
var date2 = new Date( '01-Jan-0001 ' + ruleTimeItem2.getHour() + ':' + ruleTimeItem2.getMinute() + ':' + ruleTimeItem2.getSecond() );
return areDateTimesEqual(date1, date2);
Example 3-20 Compare two partial date items
var date1 = new Date( ruleTimeItem.getYear() + '-' + ruleTimeItem.getMonth() + '-' + ruleTimeItem.getDay() + ' ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
var date2 = new Date( ruleTimeItem.getYear() + '-' + ruleTimeItem.getMonth() + '-' + ruleTimeItem.getDay() + ' ' + ruleTimeItem.getHour() + ':' + ruleTimeItem.getMinute() + ':' + ruleTimeItem.getSecond() );
return areDateTimesEqual(date1, date2);
Parent topic: Date and time functions