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 multibyte collation order like 932JPN.

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

SELECT DATEFORMAT ( StartDate, ‘yy?’) FROM Employees;

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

SELECT DATEFORMAT (StartDate, ‘yy’) + ‘?’ FROM Employees;