Datetime expressions

This section covers date-time expression evaluation rules.

A datetime expression evaluates to a DATETIME data type.

MAIN
  DEFINE r, c DATETIME YEAR TO SECOND
  LET c = CURRENT YEAR TO SECOND
  LET r = c + INTERVAL( 234-02 ) YEAR TO MONTH
END MAIN

The operands of a datetime expression can be one of:

  • A datetime literal.
  • A character string literal representing a datetime value in a format corresponding to a DATETIME type precision, for example:
    • YYYY-MM-DD hh:mm:ss.fffff => DATETIME YEAR TO FRACTION(5)
    • YYYY-MM-DD hh:mm:ss.fff => DATETIME YEAR TO FRACTION(3)
    • YYYY-MM-DD hh:mm:ss => DATETIME YEAR TO SECOND
    • YYYY-MM-DD hh:mm => DATETIME YEAR TO MINUTE
    • hh:mm:ss.fffff => DATETIME HOUR TO FRACTION(5)
    • hh:mm:ss.fff => DATETIME HOUR TO FRACTION(3)
    • hh:mm:ss => DATETIME HOUR TO SECOND
    • hh:mm => DATETIME HOUR TO MINUTE
  • A variable or constant of DATETIME type.
  • A function returning a single datetime value.
  • A unary + or - sign associated with an interval expression.
  • A CURRENT expression.
  • An EXTEND expression.

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

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