SQL Server CONVERT () function Usage Summary _mssql

Source: Internet
Author: User
Tags getdate
How to use convert:

Format:
CONVERT (Data_type,expression[,style])
Description
This style is generally in the type of time (datetime,smalldatetime) and String type (Nchar,nvarchar,char,varchar)
When they are converted to each other.
Example:
SELECT CONVERT (varchar), GETDATE (), () now
Result is
Now
---------------------------------------
09/15/2001

The style number has the following meanings when converting time
-------------------------------------------------------------------------------------------------
Style (2-bit year) | Style (4-bit year) | Input and output formats
-------------------------------------------------------------------------------------------------
- | 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)
-------------------------------------------------------------------------------------------------
The style value you can use:

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
the CONVERT function application of 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 (MB), 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 (), 130):???? ?????? 1427 10:57:49:907am
Select CONVERT (varchar), GETDATE (), 131): 18/04/1427 10:57:49:920am
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.