Returns a string representing a date expression in the specified format.
DATEFORMAT ( datetime-expression, string-expression )
datetime-expression The date/time to be converted. Must be a date, time, timestamp, or character string.
string-expression The format of the converted date.
For information on date format descriptions, see “DATE_FORMAT option”.
The following statement returns string values like “Jan 01, 1989”:
SELECT DATEFORMAT( start_date, 'Mmm dd, yyyy' ) from employee;
The following statement returns the string “Feb 19, 1987”.
SELECT DATEFORMAT( CAST ( ‘1987/02/19’ AS DATE ), ‘Mmm Dd, yyyy’ ) FROM iq_dummy
The datetime-expression to convert must be a date, time, or timestamp data type, but can also be a CHAR or VARCHAR character string. If the date is a character string, Sybase IQ implicitly converts the character string to date, time, or timestamp data type, so an explicit cast, as in the example above, is not necessary.
Any allowable date format can be used for string-expression. Date format strings cannot 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 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;
Year 2000 compliance Do not use the DATEFORMAT function to produce a string with the year value represented by only two digits. This can cause problems with year 2000 compliance even though no error has occurred.
For more information on year 2000 compliance, see “Year 2000 compliance”.