0 or 100 (*) default value mon dd yyyy hh:miam (or PM)
1 101 US MM/DD/YYYY
2 102 ANSI Yy.mm.dd
3 103 UK/France Dd/mm/yy
4 104 German 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 or 109 (*) Default value + MS Mon dd yyyy hh:mi:ss:mmmAM (or PM)
10 110 US Mm-dd-yy
11 111 Japan YY/MM/DD
ISO YYMMDD
-13 or 113 (*) European default + MS DD Mon yyyy hh:mm:ss:mmm (24h)
114-hh:mi:ss:mmm (24h)
-20 or (*) ODBC specification YYYY-MM-DD HH:MM:SS[.FFF]
-21 or 121 (*) ODBC specification (with milliseconds) Yyyy-mm-dd HH:MM:SS[.FFF]
-126 (* *) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm (excluding spaces)
-130* Kuwait DD Mon yyyy Hh:mi:ss:mmmAM
-131* Kuwait Dd/mm/yy Hh:mi:ss:mmmAM
A very powerful date formatting function in SQL Server
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 (), ():???? ?????? 1427 10:57:49:907am
Select CONVERT (varchar), GETDATE (), 131): 18/04/1427 10:57:49:920am
Common:
Select CONVERT (varchar), GETDATE (), 8): 10:57:46
Select CONVERT (varchar), GETDATE (), 24): 10:57:47
Select CONVERT (varchar), GETDATE (), 108): 10:57:49
Select CONVERT (varchar), GETDATE (), 12): 060516
Select CONVERT (varchar), GETDATE (), 23): 2006-05-16
Use of Convert conversion function in SQL
How to use convert:
////////////////////////////////////////////////////////////////////////////////////////
Format:
CONVERT (Data_type,expression[,style])
Description
This style is typically in the time type (Datetime,smalldatetime) and the 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 meaning of the style number when converting time is as follows
-------------------------------------------------------------------------------------------------
Style (2-bit for year) | Style (4-bit for year) | Input/output format
-------------------------------------------------------------------------------------------------
- | 0 or 100 | Mon dd yyyy hh:miam (or PM)
-------------------------------------------------------------------------------------------------
1 | 101 | Mm/dd/yy
-------------------------------------------------------------------------------------------------
2 | 102 | Yy-mm-dd
-------------------------------------------------------------------------------------------------
3 | 103 | Dd/mm/yy
-------------------------------------------------------------------------------------------------
4 | 104 | Dd-mm-yy
-------------------------------------------------------------------------------------------------
5 | 105 | Dd-mm-yy
-------------------------------------------------------------------------------------------------
6 | 106 | DD Mon yy
-------------------------------------------------------------------------------------------------
7 | 107 | Mon dd,yy
-------------------------------------------------------------------------------------------------
8 | 108 | Hh:mm:ss
-------------------------------------------------------------------------------------------------
- | 9 or 109 | Mon dd yyyy Hh:mi:ss:mmmmAM (or PM)
-------------------------------------------------------------------------------------------------
10 | 110 | Mm-dd-yy
-------------------------------------------------------------------------------------------------
11 | 111 | Yy/mm/dd
-------------------------------------------------------------------------------------------------
12 | 112 | Yymmdd
-------------------------------------------------------------------------------------------------
- | or 113 | DD Mon yyyy hh:mi:ss:mmm (24 hour system)
-------------------------------------------------------------------------------------------------
14 | 114 | Hh:mi:ss:mmm (24-hour system)
-------------------------------------------------------------------------------------------------
- | or 120 | Yyyy-mm-dd Hh:mi:ss (24-hour system)
-------------------------------------------------------------------------------------------------
- | or 121 | Yyyy-mm-dd Hh:mi:ss:mmm (24-hour system)
SQL Server time format