How to Do Type Casting in MySQL

Casting operations allow us to change the data type of a given value. Not all the casts are allowed, for example, you can’t cast ABC to integer, obviously.

In MySQL there is a function called cast to change the data type of a column or expression:

cast(value as type) 

-- Cast text to char
select cast(1234 as char );

-- Cast text to timestamp
select cast('2018-01-01 09:00:00' as datetime);

IN THIS PAGE