Convert date format in SQL

Source: Internet
Author: User
Tags getdate

CONVERT (Data_type,expression[,style])
CONVERT (varchar (10), field name, conversion format)

Description
This style is typically in the time type (Datetime,smalldatetime) and the string type (Nchar,nvarchar,char,varchar)
It is only used when converting to each other.

Statement result
SELECT CONVERT (varchar), GETDATE (), 0) 4:06pm
SELECT CONVERT (varchar), GETDATE (), 1) 07/15/09
SELECT CONVERT (varchar), GETDATE (), 2) 09.07.15
SELECT CONVERT (varchar), GETDATE (), 3) 15/07/09
SELECT CONVERT (varchar), GETDATE (), 4) 15.07.09
SELECT CONVERT (varchar), GETDATE (), 5) 15-07-09
SELECT CONVERT (varchar), GETDATE (), 6) 15 07 09
SELECT CONVERT (varchar), GETDATE (), 7) 07 15, 09
SELECT CONVERT (varchar), GETDATE (), 8) 16:06:26
SELECT CONVERT (varchar), GETDATE (), 9) 4:06:26:513pm
SELECT CONVERT (varchar), GETDATE (), 10) 07-15-09
SELECT CONVERT (varchar), GETDATE (), 11) 09/07/15
SELECT CONVERT (varchar), GETDATE (), 12) 090715
SELECT CONVERT (varchar), GETDATE (), 13) 15 07 2009 16:06:26:513
SELECT CONVERT (varchar), GETDATE (), 14) 16:06:26:513
SELECT CONVERT (varchar), GETDATE (), 20) 2009-07-15 16:06:26
SELECT CONVERT (varchar), GETDATE (), 21) 2009-07-15 16:06:26.513
SELECT CONVERT (varchar), GETDATE (), 07/15/09 4:06:26 PM
SELECT CONVERT (varchar), GETDATE (), 23) 2009-07-15
SELECT CONVERT (varchar), GETDATE (), 24) 16:06:26
SELECT CONVERT (varchar), GETDATE (), 25) 2009-07-15 16:06:26.513
SELECT CONVERT (varchar), GETDATE (), (+)-4:06pm
SELECT CONVERT (varchar), GETDATE (), 101) 07/15/2009
SELECT CONVERT (varchar), GETDATE (), 102) 2009.07.15
SELECT CONVERT (varchar), GETDATE (), 103) 15/07/2009
SELECT CONVERT (varchar), GETDATE (), 104) 15.07.2009
SELECT CONVERT (varchar), GETDATE (), 105) 15-07-2009
SELECT CONVERT (varchar), GETDATE (), 106) 15 07 2009
SELECT CONVERT (varchar), GETDATE (), 107) 07 15, 2009
SELECT CONVERT (varchar), GETDATE (), 108) 16:06:26
SELECT CONVERT (varchar), GETDATE (), 109) from 4:06:26:513pm
SELECT CONVERT (varchar), GETDATE (), 110) 07-15-2009
SELECT CONVERT (varchar), GETDATE (), 111) 2009/07/15
SELECT CONVERT (varchar), GETDATE (), 112) 20090715
SELECT CONVERT (varchar), GETDATE (), 113) 15 07 2009 16:06:26:513
SELECT CONVERT (varchar), GETDATE (), 114) 16:06:26:513
SELECT CONVERT (varchar), GETDATE (), 120) 2009-07-15 16:06:26
SELECT CONVERT (varchar), GETDATE (), 121) 2009-07-15 16:06:26.513
SELECT CONVERT (varchar), GETDATE (), 126) 2009-07-15t16:06:26.513
SELECT CONVERT (varchar), GETDATE (), ()??? 1430 4:06:26:513PM
SELECT CONVERT (varchar), GETDATE (), 131) 23/07/1430 4:06:26:513pm

Convert date format in SQL

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.