Subtracting two date/time values is different from subtracting a duration
from a date/time value. The operands of date/time subtraction must be
as follows:
If the first operand is a: | The second operand must be: |
---|---|
Date | A date, string representation of a date, or a duration of years, months, or days |
Time | A time, string representation of a time, or duration of hours, minutes, or seconds |
Timestamp | A duration. A timestamp can be only the first operand of subtraction. |
If the second operand is a: | The first operand must be: |
---|---|
Date | A date or string representation of a date |
Time | A time or string representation of a time |
Because character strings cannot be subtracted, a string representation of a date or time value cannot be subtracted from another string representation of a date or time value. For example, the following expression is not valid:
'1998-01-01' - '1997-01-01'
However, if you convert one of the strings to a date or time, the expression is valid. For example, the following expression is valid:
DATE('1998-01-01') - '1997-01-01'