Comparing Dates and Times

From InterBase

Go Up to Working with Dates and Times


Date and time values can be converted implicitly. For example, in the following comparison:

Table1.SomeDateField <= ‘12/31/1999’

InterBase automatically converts the string literal ‘12/31/1999’ to a DATE type for the comparison operation.

However, sometimes values do not need to be implicitly converted for an expression to make sense. For example:

‘31.5.2000’ < ‘1.6.2000’

is false because the result of comparing these two strings alphabetically is false. A string comparison of these values is valid, so InterBase does not implicitly convert them to dates, even though they “look” like dates. On the other hand:

CAST(‘31.5.2000’ AS DATE) < CAST(‘1.6.2000’ AS DATE)

is true, because the result of comparing the dates corresponding to these two strings is true. See “Implicit type conversions” in the Data Definition Guide for more information.

Advance To: