bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

SQL Server CONVERT() Function

Concept visual

SQL Server CONVERT() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Convert an expression to int:

SELECT CONVERT(int, 25.65);

Definition and Usage

The CONVERT() function converts a value (of any type) into a specified datatype.

Tip:

Also look at the CAST() function.

Syntax

Convert(

data_type(length), expression, style )

Parameter Values

Value

Description data_type Required. The datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image (length) Optional. The length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary) expression Required. The value to convert to another data type style Optional. The format used to convert between data types, such as a date or string format. Can be one of the following values:

Converting datetime to character:

Without century

With century

Input/Output

Standard

Formula

100 mon dd yyyy hh:miAM/PM

Default

Formula

101 mm/dd/yyyy

US

102 yyyy.mm.dd

Ansi

Formula

103 dd/mm/yyyy

British/French

104 dd.mm.yyyy

German

Formula

105 dd - mm - yyyy

Italian

106 dd mon yyyy

107 Mon dd, yyyy

108 hh:mm:ss

109 mon dd yyyy hh:mi:ss:mmmAM (or PM)

Formula

Default + millisec

10

Formula

110 mm - dd - yyyy

Usa

11

Formula

111 yyyy/mm/dd

Japan

12 112 yyyymmdd

Iso

13 113 dd mon yyyy hh:mi:ss:mmm Europe (24 hour clock)> 14 114 hh:mi:ss:mmm 24 hour clock 20

Formula

120 yyyy - mm - dd hh:mi:ss

ODBC canonical (24 hour clock) 21

Formula

121 yyyy - mm - dd hh:mi:ss.mmm

ODBC canonical

(24 hour clock)

Formula

126 yyyy - mm - ddThh:mi:ss.mmm

Iso8601

Formula

127 yyyy - mm - ddThh:mi:ss.mmmZ

ISO8601 (with time zone Z) 130 dd mon yyyy hh:mi:ss:mmmAM

Hijiri

Formula

131 dd/mm/yy hh:mi:ss:mmmAM

Previous

SQL Server COALESCE() Function

Next

SQL Server CURRENT_USER Function