Supported RPG Features

The SUBDUR opcode has two distinct forms depending on what appears in Factor 2.

Form 1 - Subtract a duration:

C     factor1       SUBDUR    amount:*Code  result

Factor 1 (the source) is optional; when blank, the result field is updated in-place. The duration codes and applicable types are identical to ADDDUR.

C     startDate     SUBDUR    90:*DAYS      endDate        // subtract 90 days
C     endDate       SUBDUR    2:*MONTHS     endDate        // subtract 2 months in-place

Form 2 - Calculate the difference between two date/time values:

C     factor1       SUBDUR    factor2       result:*Code

Factor 1 and Factor 2 must be compatible date/time/timestamp types, and the result field must be a numeric variable. The stored value is Factor1 − Factor2 truncated to whole units in the specified code.

C     startDate     SUBDUR    endDate       diffDays:*DAYS

The operands may be the same type, or a compatible cross-type pair: a date and a timestamp, or a time and a timestamp. A date and a time cannot be subtracted and are rejected at compile time. In a date↔timestamp difference the timestamp's time-of-day is ignored (only the date portions are compared); in a time↔timestamp difference the timestamp's date is ignored (only the time portions are compared).

C     aDate         SUBDUR    aTimestamp    diffDays:*DAYS     // date ↔ timestamp
C     aTime         SUBDUR    aTimestamp    diffMins:*MINUTES  // time ↔ timestamp
Duration Code Abbreviation Applies to
*DAYS *D DATE, TIMESTAMP
*MONTHS *M DATE, TIMESTAMP
*YEARS *Y DATE, TIMESTAMP
*HOURS *H TIME, TIMESTAMP
*MINUTES *MN TIME, TIMESTAMP
*SECONDS *S TIME, TIMESTAMP
*MSECONDS *MS TIMESTAMP only (microseconds)

The duration code must be valid for the operand types per the table above, otherwise the difference is rejected at compile time: a date difference (including date↔timestamp) accepts only *DAYS/*MONTHS/*YEARS, a time difference (including time↔timestamp) only *HOURS/*MINUTES/*SECONDS, and *MSECONDS only a timestamp-to-timestamp difference.

The (E) operation extender traps calculation errors: on failure %ERROR is set *ON and %STATUS is populated (cleared at the start of the next (E) operation). A result driven below year 0001 is an underflow, reported as %STATUS 00112; a result above year 9999 is an overflow, reported as %STATUS 00113. This applies to both SUBDUR forms. Without (E) the error propagates.