Search results
29 sie 2017 · Definition and Usage. The CAST () function converts a value (of any type) into the specified datatype. Tip: See also the CONVERT () function. Syntax. CAST (value AS datatype) Parameter Values. Technical Details. More Examples. Example. Convert a value to a CHAR datatype: SELECT CAST (150 AS CHAR); Try it Yourself » Example.
What's the difference between using the DATE(expr) function and the CAST(expr AS DATE)? DATE(expr): Extracts the date part of the date or datetime expression expr. CAST(expr AS type): The CAST() function takes an expression of any type and produces a result value of a specified type, similar to CONVERT()
CAST(timestamp_value AT TIME ZONE timezone_specifier AS DATETIME[(precision)]) timezone_specifier: [INTERVAL] '+00:00' | 'UTC' With CAST(expr AS type syntax, the CAST() function takes an expression of any type and produces a result value of the specified type.
The syntax of the MySQL CAST() function is as follows: CAST(expression AS TYPE); Code language: SQL (Structured Query Language) (sql) The target type can be any one of the following types: BINARY, CHAR, DATE, DATETIME, TIME, DECIMAL, SIGNED, or UNSIGNED.
12 maj 2023 · The MySQL CAST() function is used for converting a value from one datatype to another specific datatype. The CAST() function accepts two parameters which are the value to be converted and the datatype to which the value needs to be converted.
To ensure that the result is DATETIME, you can use CAST() to convert the first argument to DATETIME. mysql> SELECT DATE_ADD('2018-05-01',INTERVAL 1 DAY); -> '2018-05-02' mysql> SELECT DATE_SUB('2018-05-01',INTERVAL 1 YEAR); -> '2017-05-01' mysql> SELECT DATE_ADD('2020-12-31 23:59:59', -> INTERVAL 1 SECOND); -> '2021-01-01 00:00:00' mysql ...
This CAST function example shows how to cast a value to a DATETIME type. For example: mysql> SELECT CAST('2014-02-28 08:14:57' AS DATETIME); Result: '2014-02-28 08:14:57'