Comparing dates and times

Description

To compare a date to a string as a string, 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'

You can use any allowable date format 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 multibye 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;