Interval expressions

This section covers interval expression evaluation rules.

An interval evaluates to an INTERVAL data type.

MAIN
  DEFINE r, c INTERVAL HOUR TO MINUTE
  LET c = "12:45"
  LET r = c + ( DATETIME(14:02) HOUR TO MINUTE - DATETIME(10:43) HOUR TO MINUTE )
END MAIN
The operands of an interval expression must be one of:
  • An interval literal.
  • A character string literal representing an interval value in a format corresponding to an INTERVAL type class and precision, for example:
    • [-]YYYYY-MM => INTERVAL YEAR(5) TO MONTH
    • [-]YYY => INTERVAL YEAR(3) TO YEAR
    • [-]DDDDDD hh:mm:ss.fffff => INTERVAL DAY(6) TO FRACTION(5)
    • [-]hhhh:mm:ss => INTERVAL HOUR(4) TO SECOND
    • [-]mmmmmmmmm => INTERVAL MINUTE(9) TO MINUTE
    Where the number of leading digits can be less that the first INTERVAL qualifier size.
  • An integer expression using the UNITS operator.
  • A variable or constant of INTERVAL type.
  • A function returning a single interval value.
  • The result of a DATETIME subtraction.

If an interval expression includes an operand whose value is not an interval data type, the runtime system attempts to convert the value to an interval value following the data conversion rules.

If an element of an interval expression is NULL, the expression is evaluated to NULL.