CONVERT function in SQL
The CONVERT function in SQL is used to convert an expression from one data type to another. It is most used to convert between date formats, numeric formats, and string formats.
SQL Syntax
CONVERT(data_type, expression, [style])
The function has the following parameters:
- data_type: The target data type to which the expression is converted (e.g., VARCHAR, DATETIME, INT).
- expression: The value or column to be converted.
- style (optional): This is mostly used when converting to a DATETIME or VARCHAR and controls the formatting. For example, we can specify how dates are formatted (e.g., YYYY-MM-DD, DD/MM/YYYY, etc.).