Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

CONVERT

Example

Converts a value into the DATE data type format.

SELECT CONVERT(“2017-08-29”, DATE);

Definition and Usage

The CONVERT() function transforms a value into a designated datatype or character set.

Tip: For analogous conversions, explore the CAST() function.

Syntax

CONVERT(valuetype)

OR:

CONVERT(value USING charset)

Parameter Values

Parameter

Description

value

Required: The value that will undergo conversion

type

Required: The target datatype for conversion, which can be any of the following:

value

Description

DATE

Transforms a value into a DATE format: “YYYY-MM-DD”.

DATETIME

Transforms a value into the DATETIME format: “YYYY-MM-DD HH:MM:SS“.

DECIMAL

Converts a value to a DECIMAL format, allowing specification of the maximum number of digits (M) and the number of digits after the decimal point (D).

TIME

Transforms a value into the TIME format: “HH:MM:SS“.

CHAR

Converts a value into a fixed-length string format (CHAR).

NCHAR

Converts a value into an NCHAR format, which produces a string using the national character set.

SIGNED

Converts a value into a SIGNED format, specifically a signed 64-bit integer.

UNSIGNED

Converts a value into an UNSIGNED format, specifically an unsigned 64-bit integer.

BINARY

Converts a value into a BINARY format, representing it as a binary string.

charset

Required: The character set to which the conversion is applied

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Converts a value into the CHAR data type.

SELECT CONVERT(150, CHAR);

Example

Converts a value into the TIME data type.

SELECT CONVERT(“14:06:10”, TIME);

Example

Converts a value into the LATIN1 character set.

SELECT CONVERT(“W3Schools.com” USING latin1);