Methods for converting date formats using the CONVERT function in SQL Server _mssql

Source: Internet
Author: User
Tags getdate odbc
SQL Server Chinese version of the default Date field datetime format is YYYY-MM-DD Thh:mm:ss.mmm
For example:
Select GETDATE ()

Sorted out the date format conversion methods that you might often use in SQL Server:

examples are as follows:

Select CONVERT (varchar, GETDATE (), 120)
2004-09-12 11:06:08
Select replace (replace (varchar, GETDATE (), 120), '-', '), ', ', ': ', '
20040912110608
Select CONVERT (varchar (), GETDATE (), 111)
2004/09/12
Select CONVERT (varchar (), GETDATE (), 112)
20040912
Select CONVERT (varchar (), GETDATE (), 102)
2004.09.12
Select CONVERT (varchar (), GETDATE (), 101)
09/12/2004
Select CONVERT (varchar (), GETDATE (), 103)
12/09/2004
Select CONVERT (varchar (), GETDATE (), 104)
12.09.2004
Select CONVERT (varchar (), GETDATE (), 105)
12-09-2004
Select CONVERT (varchar (), GETDATE (), 106)
12 09 2004
Select CONVERT (varchar (), GETDATE (), 107)
09 12, 2004
Select CONVERT (varchar (), GETDATE (), 108)
11:06:08
Select CONVERT (varchar (), GETDATE (), 109)
09 12 2004 1
Select CONVERT (varchar (), GETDATE (), 110)
09-12-2004
Select CONVERT (varchar (), GETDATE (), 113)
12 09 2004 1
Select CONVERT (varchar (), GETDATE (), 114)
11:06:08.177
Select GETDATE ()
Results: 2003-12-28 16:52:00.107
Select CONVERT (char (8), GETDATE (), 112)
Results: 20031228
Select CONVERT (char (8), GETDATE (), 108)
Result: 16:52:00
Select CONVERT (char (8), GETDATE (), 112)

Date Format
The rules are as follows:
1 101 American Mm/dd/yyyy
2 102 ANSI Yy.mm.dd
3 103 British/French DD/MM/YY
4 104 German Dd.mm.yy
5 105 Italian Dd-mm-yy
6 106-dd Mon yy
7 107-mon DD, yy
8 108-HH:MM:SS
-9 or 109 (*) default + millisecond Mon dd yyyy hh:mi:ss:mmmAM (or PM)
10 110 American Mm-dd-yy
11 111 Japanese Yy/mm/dd
112 ISO YYMMDD
-13 or 113 (*) Euro defaults + millisecond 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 (without spaces)
-130* Kuwait DD Mon yyyy Hh:mi:ss:mmmAM
-131* Kuwaiti Dd/mm/yy Hh:mi:ss:mmmAM
About the format conversion of fields in Emaker and the operation code between fields can be added to the properties of "format conversion (read out)" and "format conversion (write)", table field settings in the "field" position can also be flexible add functions. For example: ' AF ' +id or id+ '/' +pwd, convert (varchar, F1),
Convert (int,%)-19110000 (read out)
Convert (char (8), convert (int,%) +19110000) (write)
Implement the total operation of the row, and so on. Add:% system variable%, then call the system variable set in the Emaker system.
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.