Datetime expressions

A datetime expression resolves to a time value (date, interval, time, or timestamp, depending upon the context used). Expressions are specified in various situations; for example, on the right side of an assignment statement. A datetime expression may be composed of any of these:

The following rules apply for datetime arithmetic calculations, some of which are summarized in the table below:

The following table summarizes the types of arithmetic operations that can be performed upon dates, intervals and timestamps:
Operand 1 Operator Operand 2 Result Comments
DATE - DATE NUMBER  
DATE +/- NUMBER DATE  
NUMBER + DATE DATE  
         
TIME STAMP - TIMESTAMP INTERVAL INTERVAL(dd, ss) unless Operand 1 and Operand 2 are both any of the following:

  • TIMESTAMP(yyyy)

  • TIMESTAMP(yyyymm)

  • TIMESTAMP(MM) in which case the result is INTERVAL(yyyymm)

DATE - TIMESTAMP INTERVAL INTERVAL(ddssmmffffff)
TIME STAMP - DATE INTERVAL INTERVAL(ddhhmmssffffff)
         
TIME STAMP +/- INTERVAL TIMESTAMP  
INTERVAL + TIMESTAMP TIMESTAMP  
         
DATE +/- INTERVAL TIMESTAMP  
INTERVAL + DATE TIMESTAMP  
         
INTERVAL +/- INTERVAL INTERVAL Operand1 and Operand2 must be compatible types.
INTERVAL *// NUMBER INTERVAL  

Related reference
Assignments
Expressions
Items
Logical expressions
Numeric expressions
Operators and precedence
Primitive types
sysLib.dateValue
sysLib.extendTimeStampValue
sysLib.intervalValue
sysLib.timeValue
sysLib.timeStampValue
Text expressions
Text formatting (system words)
Substrings