Comparing dates and times

Description

If you wish to compare a date to a string as a string, you must use the DATEFORMAT function or CAST function to convert the date to a string before comparing. For example:


DATEFORMAT(invoice_date,'yyyy/mm/dd') = '1992/05/23'

Any allowable date format can be used for the DATEFORMAT string expression.

Date format strings must not contain any multibyte characters. Only single-byte characters are allowed in a date/time/datetime format string, even when the collation order of the database is a multi-bye collation order like SJIS2.

If '?' represents a multibyte character, then the following query fails:

SELECT DATEFORMAT ( start_date, ‘yy?’) FROM employee;

Instead, move the multibyte character outside of the date format string using the concatenation operator:

SELECT DATEFORMAT (start_date, ‘yy’) + ‘?’ FROM employee;