The SUBDUR operation can also be used to calculate a duration between:
- Two dates
- A date and a timestamp
- Two times
- A time and a timestamp
- Two timestamps
The data types in factor 1 and factor 2 must be compatible types
as specified above.
Factor 1 is required and must contain a Date, Time or Timestamp
field, subfield, array, array element, constant or literal.
Factor 2 is required and must also contain a Date, Time or Timestamp
field, array, array element, literal or constant.
The following duration codes are valid:
- For two dates or a date and a timestamp: *DAYS (*D), *MONTHS (*M),
and *YEARS (*Y)
- For two times or a time and a timestamp: *SECONDS (*S), *MINUTES
(*MN), and *HOURS (*H)
- For two timestamps: *MSECONDS (*MS), *SECONDS (*S), *MINUTES (*MN),
*HOURS (*H), *DAYS (*D), *MONTHS (*M), and *YEARS (*Y).
The result is a number of whole units, with any remainder
discarded. For example, 61 minutes is equal to 1 hour and 59 minutes
is equal to 0 hours.
The result field consists of two subfactors. The first is the
name of a zero decimal numeric field, array or array element in which
the result of the operation will be placed. The second subfactor
contains a duration code denoting the type of duration. The result
field will be negative if the date in factor 1 is earlier than the
date in factor 2.
For more information on working with date-time fields see
Date Operations.
Note: Calculating a micro-second Duration
(*mseconds) can exceed the 15 digit system limit for Durations and
cause errors or truncation. This situation will occur when there is
more than a 32 year and 9 month difference between the factor 1 and
factor 2 entries.