MySQL CONVERT() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL CONVERT() Function

❮ MySQL Functions

Example

Convert a value from one datatype to another datatype:

SELECT CONVERT("2017-08-29", DATE);
Try it Yourself »

Definition and Usage

The CONVERT() function converts a value from one datatype to another, or one character set to another.

Tip: See also the CAST() function.

Syntax

CONVERT(value, type)

OR:

CONVERT(value USING charset)

Parameter Values

Parameter Description
value Required. The value to convert
type Required. The datatype to convert to. Can be one of the following:
Value Description
DATE Converts value to DATE type. Format is "YYYY-MM-DD" (Supported range is from "1000-01-01" to "9999-12-31")
DATETIME Converts value to DATETIME type. Format is "YYYY-MM-DD HH:MM:SS" (Supported range is from "1000-01-01 00:00:00" to "9999-12-31 23:59:59")
TIME Converts value to TIME type. Format is "HH:MM:SS" (Supported range is from "-838:59:59" to "838:59:59")
CHAR Converts value to CHAR type, which is a fixed length string
SIGNED Converts value to SIGNED type, which is a signed 64-bit integer
UNSIGNED Converts value to UNSIGNED type, which is an unsigned 64-bit integer
BINARY Converts value to BINARY type, which is a binary string
charset Required. The character set to convert to

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0.2

More Examples

Example

Convert a value from one datatype to another datatype:

SELECT CONVERT(150, CHAR);
Try it Yourself »

Example

Convert a value from one datatype to another datatype:

SELECT CONVERT("14:06:10", TIME);
Try it Yourself »

Example

Convert a value from one character set to another:

SELECT CONVERT("W3Schools.com" USING latin1);
Try it Yourself »

❮ MySQL Functions