function
Returns an expression that is converted to the provided data type.
Grammar
CONVERT (data type, expression [, Format-style])
Cases:
CONVERT (varchar (8), GETDATE (), 112)
parameters
The data type to which the type expression will be converted.
Expression to convert.
Format-style for converting a string to a date or time data type and to the reverse conversion process, Format-style is a style code that describes the date format string to use. The value of the Format-style parameter has the following meanings: No century (yy) with century (yyyy) output
Note:
By default, SQL Server interprets two-digit years based on the cutoff year 2049. In other words, the two-digit year 49 is interpreted as 2049, and the two-digit year 50 is interpreted as 1950. Many client applications, such as automation object-based applications, use the cutoff year 2030. SQL Server provides a digit year cutoff configuration option to change the cutoff years used by SQL Server for consistent date processing. We recommend that you specify a four-digit year.
Style (2-bit for year) | Style (4-bit for year) | Input/output format
------------------------------------------------------------------------------------------------------------
0 | 100 | Mon dd yyyy hh:miam (or PM)
------------------------------------------------------------------------------------------------------------
1 | 101 USA | Mm/dd/yy
------------------------------------------------------------------------------------------------------------
2 | 102 ANSI | Yy-mm-dd
------------------------------------------------------------------------------------------------------------
3 | 103 Anglo-French | Dd/mm/yy
------------------------------------------------------------------------------------------------------------
4 | 104 Germany | Dd.mm.yy
------------------------------------------------------------------------------------------------------------
5 | 105 Italy | Dd-mm-yy
------------------------------------------------------------------------------------------------------------
6 | 106 | DD Mon yy
------------------------------------------------------------------------------------------------------------
7 | 107 | Mon dd,yy
------------------------------------------------------------------------------------------------------------
8 | 108 | Hh:mm:ss
------------------------------------------------------------------------------------------------------------
9 | 109 | Mon dd yyyy Hh:mi:ss:mmmmAM (or PM)
------------------------------------------------------------------------------------------------------------
10 | 110 USA | Mm-dd-yy
------------------------------------------------------------------------------------------------------------
11 | 111 Japan | Yy/mm/dd
------------------------------------------------------------------------------------------------------------
12 | ISO | Yymmdd
------------------------------------------------------------------------------------------------------------
13 | 113 Euro Default | DD Mon yyyy hh:mi:ss:mmm (24 hour system)
------------------------------------------------------------------------------------------------------------
14 | 114 | Hh:mi:ss:mmm (24-hour system)
------------------------------------------------------------------------------------------------------------
20 | ODBC Specification | Yyyy-mm-dd Hh:mi:ss (24-hour system)
------------------------------------------------------------------------------------------------------------
21 | 121 | Yyyy-mm-dd Hh:mi:ss:mmm (24-hour system)
T-SQL time format convert ()