Rules & Date Calculations

Date calculations where you want to compute the difference between two dates, giving a numeric result are an exception to the above syntax. This is because you desire a numeric result and you cannot assign a date to a number without causing an error. The correct syntax to calculate the difference between two dates (DAT_1 and DAT_2) and place the result in the field DIFF is:

DIFF = (DAT1 - DAT2);

Date differences in rules may specify qualifiers to get results computed in units other than days. The qualifiers are {seconds}, {minutes}, {hours}, and {days}. Each of these results in an integral value after the date difference is computed. The fractional part of the computation is truncated, not rounded. This implies that the meaning is "the integral number of between the two dates".

Example:

## compute number of seconds between two dates
X_NUMBER = (X_DATE1 - X_DATE2).{seconds};
## compute integral number of days between two dates
X_DECIMAL = (X_DATE1 - X_DATE2).{days};
## compute total (including fractional) days between two dates
X_DECIMAL_DAYS = (X_DATE1 - X_DATE2);

You can specify a specific business calendar to use with date calculations. This is done with the calendar directive. For example, if you use the WEEKDAY calendar provided with ExtraView, and you have a calculation such as:

 
<== calendar WEEKDAY ==>
DATE_RESULT  = SYSDATE;
DATE_RESULT += 3;

where SYSDATE is a Thursday, the result will be Tuesday, i.e. it is 3 workdays, plus the 2 weekend days.

If you add 0 to a date using a business calendar, the result will skip to the first work day beyond that date if that date is not a work day.

Null date and day field values have special treatment. When a date or day field has a null value, and is being used in a calculation, it is assumed the null date is January 1st, 1900. This avoids errors and null results occuring. However, tests on date and day type fields with value qualifiers such as date_field.{is null} and date_field.{not null} return true or false depending on whether there is a null value.

Date fields and Day Fields

Using a Day type field within a Business Rule is consistent when it is compared or combined in expressions with other Day type fields. When compared with Date fields, the Date is converted to a Day value using the user's time zone (to which the Date value is, by definition, relative) and the comparison is done with a Day field to Day field comparison or calculation.