%DIFF Function

%DIFF built-in function produces the difference (duration) between two date or time values. The first and second parameters must be the same or compatible types.

%DIFF (Op1, Op2, {*MSECONDS | *SECONDS | *MINUTES | *HOURS | *DAYS | *MONTHS | *YEARS}) 
        

Parameters

Op1, Op2

Required. These two parameters must be the same or compatible types. The following combination are valid:

  • Date and Date
  • Time and Time
  • Timestamp and Timestamp
  • Date and Timestamp
  • Time and Timestamp

*MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, *YEARS

Required. This specifies the duration. Valid codes depend upon the previous parameters as follows:

  • For Date and Date, you can specify *DAYS, *MONTHS, or *YEARS.
  • For Time and Time, you can specify *SECONDS, *MINUTES, or *HOURS.
  • For Timestamp and Timestamp, you can specify *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, or *YEARS.
  • For Date and Timestamp, you can specify *DAYS, *MONTHS, or *YEARS. Note Only the date portion of the Timestamp is considered.
  • For Time and Timestamp, you can specify *SECONDS, *MINUTES, or *HOURS. NOTE : Only the time portion of the Timestamp is considered.

Remarks

The result will be rounded down with any remainder discarded. For example, 61 minutes is equal to 1 hour, and 59 minutes is equal to 0 hours. Visual RPG places an 18-digit limit on durations. A duration with more than 15 significant digits will cause errors or truncation. The value returned by this function is compatible with both type numeric and type duration. You can add or subtract the result to a number (type numeric) or a date, time, or timestamp (type duration). See Adding or Subtracting Dates for more information.

See Also

Built-in Function Overview

Date and Time Topics

Adding or Subtracting Dates

%DAYS

%HOURS

%MINUTES

%MONTHS

%MSECONDS

%SECONDS

%YEARS

ADDDUR

SUBDUR