Date formatting functions for SQL Server functions

Source: Internet
Author: User
Tags getdate

Date formatting functions for SQL Server functions

For some of the students who write SQL Server execution statements, date Format function of the mastery and application is very important, today we mainly to enumerate some of the commonly used date-time format function, see below:

We can execute a new query through SSMS to see the results of the execution; In fact, we are the most common and most commonly used two formats:

Current date + time

Select CONVERT (varchar), GETDATE (), 120)

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/A5/F1/wKioL1nF9P7Q1o-PAAEhrcd-U8c483.png-wh_500x0-wm_ 3-wmp_4-s_1712892418.png "title=" 1.png "alt=" Wkiol1nf9p7q1o-paaehrcd-u8c483.png-wh_50 "/>

Date of current system

Select CONVERT (varchar), GETDATE (), 23)

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/07/40/wKiom1nF9VCxkoJMAAELZNrNmqA030.png-wh_500x0-wm_ 3-wmp_4-s_3844169088.png "title=" 2.png "alt=" Wkiom1nf9vcxkojmaaelznrnmqa030.png-wh_50 "/>

See more of the following formats:

Select convert (varchar),  getdate (),  0): 05 16 2006 10:57amselect  CONVERT (varchar),  getdate (),  1):  05/16/06select convert (varchar),  getdate (),  2):  06.05.16select convert (varchar),  getdate (),  3): 16/05/06select  CONVERT (varchar),  getdate (),  4):  16.05.06select convert (varchar),  getdate (),  5):  16-05-06select convert (varchar),  getdate (),  6): 16 05  06select convert (varchar),  getdate (),  7):  05 16, 06select convert ( varchar (+),  getdate (),  8):  10:57:46select convert (varchar),  getdate (),  9):  05 16 2006 10:57:46:827amselect convert (varchar),  getdate (),  10):  05-16-06select convert (varchar),  getdate (),  11):  06/05/16select convert ( varchar (+),  getdate (),  12):  060516select convert (varchar),  getdate (),  13): 16 05 2006  10:57:46:937select convert (varchar),  getdate (),  14):  10:57:46:967select convert ( varchar (+),  getdate (),  20):  2006-05-16 10:57:47select convert (varchar),  GETDATE (),  21):  2006-05-16 10:57:47.157select convert (varchar),  getdate (),  :  05/16/06 10:57:47 amselect convert (varchar),  getdate (),  23):  2006-05-16select convert (varchar),  getdate (),  24):  10:57:47select convert (varchar (+),  getdate (),  25):  2006-05-16 10:57:47.250select convert (varchar),  GETDATE (),  100):  05 16 2006 10:57amselect convert (varchar),  getdate (),  101):  05/16/2006select convert (varchar),  getdate (),  102):  2006.05.16select  convert (varchar), &NBSp GETDATE (),  103):  16/05/2006select convert (varchar),  getdate (),  104):  16.05.2006select convert (varchar),  getdate (),  105):  16-05-2006select convert ( varchar (+),  getdate (),  106):  16 05 2006select convert (varchar),  GETDATE (),  107):  05 16, 2006select convert (varchar),  getdate (),  108):  10:57:49select convert (varchar),  getdate (),  109): 05 16 2006  10:57:49:437amselect convert (varchar),  getdate (),  110):  05-16-2006select convert ( varchar (+),  getdate (),  111):  2006/05/16select convert (varchar),  getdate (),  112):  20060516select convert (varchar),  getdate (),  113): 16 05  2006 10:57:49:513select convert (varchar),  getdate (),  114):  10:57:49:547select  convert (varchar),  getdate (),  120):  2006-05-16 10:57:49select convert (varchar),  getdate (),  121):  2006-05-16 10:57:49.700select convert (varchar),  getdate (),  126):  2006-05-16t10 : 57:49.827select convert (varchar),  getdate (),  130): 18 ????  ??????  1427 10:57:49:907amselect convert (varchar),  getdate (),  131):  18/04/1427  10:57:49:920am

This article from "Gao Wenrong" blog, declined reprint!

Date formatting functions for SQL Server functions

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.