partialDateDiff( )

Find the difference between two dates.

Syntax

As far as this function may contain partial date components, dates are compared up to the first defined part for both dates (second/minute/hour/day/month/year). For example, if the following two dates are compared:
  • 01-Jun-2011 11:12:14
  • 02-Jan-2011 17:UNK:UNK
The first defined part is hour, so dates will be compared as:
  • 01-Jun-2011 11
  • 02-Jan-2011 17
partialDateDiff(date1,isPartial1,date2,isPartial2,Datepart)

Parameters

Note:

This is a JavaScript function. Quotes are not needed in the rule variable name.
Parameter Required/Optional Description
date1 Required First rule variable of date or date/time type to be compared.

Supports Date, Datetime and Time type variables, either full or with partial components.

isPartial1 Required Boolean value (true or false) to indicate if date1 is partial or not.
date2 Required Second rule variable of date or date/time type to be compared.

Supports Date, Datetime and Time type variables, either full or with partial components.

isPartial2 Required Boolean value (true or false) to indicate if date2 is partial or not.
Datepart Required
String that specifies the part of the variable to compare. May contain one of the following values:
  • 'Day'
  • 'Year'
  • 'Hour'
  • 'Minute'
  • 'Second'

Note:

When datepart is 'Day' or 'Year', time elements are not considered in difference calculation

Return value

Number that represents the difference between the two dates in units of the given date part selected. For example if you added 'Day' as the datepart to be compared, the difference is in days.

Differences are returned using the closest integer less than or equal to the exact value. For example, if the difference between 2 dates is 1.5 hours, then 1 hour is returned as the difference in hours.

Examples

Example 3-42 Compare one full DateTime Item with one partial DateTime Item

// Given 2 form questions of type DateTime are defined in the rule as variables
// date1 is a full date containing the value of 05-NOV-2021
// date2 is a partial date containing the value of UNK-OCT-2021
if(partialDateDiff(date1, false, date2, true, 'Day') > 28){
    returntrue;
}
else{
    returnfalse; // Query is triggered if the difference between dates is greater than 28 days.
}  

// The difference between dates is '31', the query will not be triggered