Datetime comparisons

A DATE, TIME, or TIMESTAMP value can be compared either with another value of the same data type, a datetime constant of the same data type, or with a string representation of that data type. A date value or a string representation of a date can also be compared with a TIMESTAMP, where the missing time information for the date value is assumed to be all zeros. All comparisons are chronological, which means the farther a point in time is from January 1, 0001, the greater the value of that point in time.

Comparisons involving TIME values and string representations of time values always include seconds. If the string representation omits seconds, zero seconds are implied. The time 24:00:00 compares greater than the time 00:00:00.

Comparisons involving TIMESTAMP values are evaluated according to the following rules:
  • When comparing timestamp values with different precisions, the higher precision is used for the comparison and any missing digits for fractional seconds are assumed to be zero.
  • When comparing a timestamp value with a string representation of a timestamp, the string representation is first converted to TIMESTAMP(12).
  • Timestamp comparisons are chronological without regard to representations that might be considered equivalent. Thus, the following predicate is true:
       TIMESTAMP('1990-02-23-00.00.00') > '1990-02-22-24.00.00'