Introduction to the CONVERT () function of SQL Server

Source: Internet
Author: User
Tags getdate

Definition and Usage:

The CONVERT () function is a general function that converts a date to a new data type.

The CONVERT () function can display date/time data in different formats.


Grammar:

CONVERT (data_type (length), Data_to_be_converted,style)

data_type (length) Specifies the target data type (with optional lengths). The data_to_be_converted contains values that need to be converted. style Specifies the date/time output format.

The style value that can be used:

Style idstyle Format 100 or 0mon dd yyyy hh:miam (or PM) 101MM/DD/YY102YY.MM.DD103DD/MM/YY104DD.MM.YY105DD-MM-YY106DD Mon yy107 Mon dd, yy108hh:mm:ss109 or 9mon dd yyyy hh:mi:ss:mmmAM (or PM) 110mm-dd-yy111yy/mm/dd112yymmdd113 or 13dd mon yyyy hh:mm:ss : Mmm (24h) 114hh:mi:ss:mmm (24h) 120 or 20yyyy-mm-dd Hh:mi:ss (24h) 121 or 21yyyy-mm-dd hh:mi:ss.mmm (24h) 126yyyy-mm-ddthh: Mm:ss.mmm (no spaces) 130dd Mon yyyy hh:mi:ss:mmmam131dd/mm/yy Hh:mi:ss:mmmAM

Instance

The following script uses the CONVERT () function to display different formats. We will use the GETDATE () function to get the current date/time:

CONVERT (VARCHAR), GETDATE ())
CONVERT (VARCHAR), GETDATE (), ()
CONVERT (VARCHAR (one), GETDATE (), 106)
CONVERT (VARCHAR), GETDATE (), 113)

The results are similar:

Dec 11:45 PM
12-29-2008
Dec
Dec 16:25:46.635

Original address: http://bbs.delit.cn/thread-184-1-1.html

Reprint please specify the source:

Author: metric Technology http://www.delit.cn

Introduction to the CONVERT () function of SQL Server

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.