T-SQL time format convert ()

Source: Internet
Author: User

function
Returns an expression that is converted to the provided data type.
Grammar

CONVERT (data type, expression [, Format-style])

Cases:

CONVERT (varchar (8), GETDATE (), 112)


parameters
The data type to which the type expression will be converted.
Expression to convert.
Format-style for converting a string to a date or time data type and to the reverse conversion process, Format-style is a style code that describes the date format string to use. The value of the Format-style parameter has the following meanings: No century (yy) with century (yyyy) output

Note:

By default, SQL Server interprets two-digit years based on the cutoff year 2049. In other words, the two-digit year 49 is interpreted as 2049, and the two-digit year 50 is interpreted as 1950. Many client applications, such as automation object-based applications, use the cutoff year 2030. SQL Server provides a digit year cutoff configuration option to change the cutoff years used by SQL Server for consistent date processing. We recommend that you specify a four-digit year.


Style (2-bit for year) | Style (4-bit for year) | Input/output format
------------------------------------------------------------------------------------------------------------
0 | 100 | Mon dd yyyy hh:miam (or PM)
------------------------------------------------------------------------------------------------------------
1 | 101 USA | Mm/dd/yy
------------------------------------------------------------------------------------------------------------
2 | 102 ANSI | Yy-mm-dd
------------------------------------------------------------------------------------------------------------
3 | 103 Anglo-French | Dd/mm/yy
------------------------------------------------------------------------------------------------------------
4 | 104 Germany | 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 | 109 | Mon dd yyyy Hh:mi:ss:mmmmAM (or PM)
------------------------------------------------------------------------------------------------------------
10 | 110 USA | Mm-dd-yy
------------------------------------------------------------------------------------------------------------
11 | 111 Japan | Yy/mm/dd
------------------------------------------------------------------------------------------------------------
12 | ISO | Yymmdd
------------------------------------------------------------------------------------------------------------
13 | 113 Euro Default | DD Mon yyyy hh:mi:ss:mmm (24 hour system)
------------------------------------------------------------------------------------------------------------
14 | 114 | Hh:mi:ss:mmm (24-hour system)
------------------------------------------------------------------------------------------------------------
20 | ODBC Specification | Yyyy-mm-dd Hh:mi:ss (24-hour system)
------------------------------------------------------------------------------------------------------------
21 | 121 | Yyyy-mm-dd Hh:mi:ss:mmm (24-hour system)

T-SQL time format convert ()

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.