UNITS

The UNITS operator converts an integer to an interval.

Syntax

expr UNITS qual[(scale)]
where qual can be one of:
  YEAR
  MONTH
  DAY
  HOUR
  MINUTE
  SECOND
  FRACTION(1-6)
  1. expr is an integer expression.

Usage

The UNITS operator converts an integer expression to an INTERVAL value expressed in a single unit of time that you specify after the UNITS keyword.

For the qualifiers YEAR, MONTH, DAY, HOUR and SECOND, if the left-hand expression evaluates to a decimal number, any fractional part is discarded before the UNITS operator is applied. However, when using UNITS FRACTION, the expression can be a decimal number where the integer part is interpreted as a number of seconds, and the decimal part as the fraction of a second.

UNITS has a higher precedence than any arithmetic or boolean operator. As a result, a left-hand arithmetic expression that uses a UNITS operator must be enclosed in parentheses. For example, 10 + 20 UNITS MINUTES will be evaluated as 10 + (20 UNITS MINUTES) and give a conversion error. It must be written (10 + 20) UNITS MINUTES to get the expected result.

Because the difference between two DATE values is an integer count of days rather than an INTERVAL data type, you might want to use the UNITS operator to convert such differences explicitly to INTERVAL values.

Example

MAIN
  DEFINE d DATE
  LET d = TODAY + 200
  DISPLAY (d - TODAY) UNITS DAY
END MAIN