Example
Convert a value to a DATE datatype:
SELECT CAST("2017-08-29" AS DATE);
Definition and Usage
The CAST() function converts a value (of any type) into the specified datatype.
Syntax
CAST(value AS datatype)
Parameter Values
Parameter | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Required. The value to convert | ||||||||||||||||||||
datatype | Required. The datatype to convert to. Can be one of the following:
|
Technical Details
Works in: | From MySQL 4.0 |
---|
More Examples
Example
Convert a value to a CHAR datatype:
SELECT CAST(150 AS CHAR);
Example
Convert a value to a TIME datatype:
SELECT CAST("14:06:10" AS TIME);
Example
Convert a value to a SIGNED datatype:
SELECT CAST(5-10 AS SIGNED);