Use this function to convert a non-date value to a DATE type

Syntax


DATE ( expression )

Arguments

  • expression: can be any of the following data_types:

    • DATE

    • TIMESTAMP

    • positive number less than 2,932,897

    • string value properly formatted to represent a DATE or TIMESTAMP

    • a non-LONG VARCHAR string of length 7, in the form yyyddd, with yyy as the year and ddd as the day of the year. Each must be 3 characters long exactly. For example, to specify day 1, specify ddd as ‘001’.

Returns

  • A DATE value. Returns NULL if expression is NULL.

  • If expression is a positive number, returns a DATE value which is expression-1 days after January 1, 1970.

Examples


SELECT orderDay, DATE(orderDay) AS orderDayDate FROM MYSQL.inventory.cust;

VALUES DATE(10)
-- Returns 1970-01-10