Syntax format:
CONVERT (Data_type,expression[,style])
Description: This style is typically in time type (datetime,smalldatetime) and String type (Nchar,nvarchar,char,varchar)
It is only used when converting to each other.
Example:
SELECT CONVERT (varchar (+), GETDATE (), 101) Now
Result is
Now
---------------------------------------
09/15/2001
The style number has the following meaning when converting time: The style value that can be used.
Style ID |
Style Format |
100 or 0 |
Mon dd yyyy hh:miam (or PM) |
101 |
Mm/dd/yy |
102 |
Yy.mm.dd |
103 |
Dd/mm/yy |
104 |
Dd.mm.yy |
105 |
Dd-mm-yy |
106 |
DD Mon yy |
107 |
Mon DD, yy |
108 |
Hh:mm:ss |
109 or 9 |
Mon dd yyyy hh:mi:ss:mmmAM (or PM) |
110 |
Mm-dd-yy |
111 |
Yy/mm/dd |
112 |
Yymmdd |
113 or 13 |
DD Mon yyyy hh:mm:ss:mmm (24h) |
114 |
Hh:mi:ss:mmm (24h) |
120 or 20 |
Yyyy-mm-dd Hh:mi:ss (24h) |
121 or 21 |
Yyyy-mm-dd hh:mi:ss.mmm (24h) |
126 |
Yyyy-mm-ddthh:mm:ss.mmm (no spaces) |
130 |
DD Mon yyyy hh:mi:ss:mmmAM |
131 |
Dd/mm/yy Hh:mi:ss:mmmAM
|
SQL Server's CONVERT function application
Select CONVERT (varchar), GETDATE (), 0): 2006 10:57am
Select CONVERT (varchar), GETDATE (), 1): 05/16/06
Select CONVERT (varchar), GETDATE (), 2): 06.05.16
Select CONVERT (varchar), GETDATE (), 3): 16/05/06
Select CONVERT (varchar), GETDATE (), 4): 16.05.06
Select CONVERT (varchar), GETDATE (), 5): 16-05-06
Select CONVERT (varchar), GETDATE (), 6): 16 05 06
Select CONVERT (varchar), GETDATE (), 7): 05 16, 06
Select CONVERT (varchar), GETDATE (), 8): 10:57:46
Select CONVERT (varchar), GETDATE (), 9): 2006 10:57:46:827am
Select CONVERT (varchar), GETDATE (), 10): 05-16-06
Select CONVERT (varchar), GETDATE (), 11): 06/05/16
Select CONVERT (varchar), GETDATE (), 12): 060516
Select CONVERT (varchar), GETDATE (), 13): 16 05 2006 10:57:46:937
Select CONVERT (varchar), GETDATE (), 14): 10:57:46:967
Select CONVERT (varchar), GETDATE (), 20): 2006-05-16 10:57:47
Select CONVERT (varchar), GETDATE (), 21): 2006-05-16 10:57:47.157
Select CONVERT (varchar), GETDATE (): 05/16/06 10:57:47 AM
Select CONVERT (varchar), GETDATE (), 23): 2006-05-16
Select CONVERT (varchar), GETDATE (), 24): 10:57:47
Select CONVERT (varchar), GETDATE (), 25): 2006-05-16 10:57:47.250
Select CONVERT (varchar), GETDATE (), (+): 2006 10:57am
Select CONVERT (varchar), GETDATE (), 101): 05/16/2006
Select CONVERT (varchar), GETDATE (), 102): 2006.05.16
Select CONVERT (varchar), GETDATE (), 103): 16/05/2006
Select CONVERT (varchar), GETDATE (), 104): 16.05.2006
Select CONVERT (varchar), GETDATE (), 105): 16-05-2006
Select CONVERT (varchar), GETDATE (), 106): 16 05 2006
Select CONVERT (varchar), GETDATE (), 107): 05 16, 2006
Select CONVERT (varchar), GETDATE (), 108): 10:57:49
Select CONVERT (varchar), GETDATE (), 109): 2006 10:57:49:437am
Select CONVERT (varchar), GETDATE (), 110): 05-16-2006
Select CONVERT (varchar), GETDATE (), 111): 2006/05/16
Select CONVERT (varchar), GETDATE (), 112): 20060516
Select CONVERT (varchar), GETDATE (), 113): 16 05 2006 10:57:49:513
Select CONVERT (varchar), GETDATE (), 114): 10:57:49:547
Select CONVERT (varchar), GETDATE (), 120): 2006-05-16 10:57:49
Select CONVERT (varchar), GETDATE (), 121): 2006-05-16 10:57:49.700
Select CONVERT (varchar), GETDATE (), 126): 2006-05-16t10:57:49.827
Select CONVERT (varchar), GETDATE (), (): APR 2006 10:57:49:907am
Select CONVERT (varchar), GETDATE (), 131): 18/04/2006 10:57:49:920am
The-CONVERT () function of the SQL Server database family