Date format conversions in SQL Server convert (varchar, GETDATE (), 120)

Source: Internet
Author: User
Tags getdate

CONVERT (varchar, GETDATE (), 120)This is a function of the MSSQL database, the function of the CONVERT function is to convert the data type. and the Convert (char (), opendate,120) You're asking is a function that formats the date field and converts it into character formatting. Next, the three parameters in your function are explained separately: 1.char (20), is the target data type and length to be converted to, here you can also use varchar (20), or varchar (10), if 20 is used, the converted string can be 20 length, If it is 10, only the first 10 digits are taken. The latter is omitted. 2.openDate, is a date field, this does not have to explain too much. 3.120, is the format of the date format encoding, in addition to 120, there are many encodings, each encoding corresponds to a conversion format,

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 (), 20040912
Select CONVERT (varchar (), GETDATE (), 102) 2004.09.12
Select CONVERT (varchar), GETDATE (), 101 ) 09/12/2004
Select CONVERT (varchar (104), GETDATE (), 103) 12/09/2004
Select CONVERT (varchar), GETDATE (),) 12.09.2004
Select CONVERT (varchar), GETDATE (), 12-09-2004
Select CONVERT (varchar), GETDATE (), 106) 12 2004
Select CONVERT (varchar (11), GETDATE (), 107), 2004
Select CONVERT (varchar, GETDATE (), 108): 06:08
Select CONVERT (varchar), GETDATE (), 109) 2004 1
Select CONVERT (varchar (), GETDATE (), 110) 09-12 -2004
Select CONVERT (varchar (), GETDATE (), 113) 2004 1
Select CONVERT (varchar), GETDATE (), 114) 11:06 : 08.177

Change getdate () to the appropriate field

Date format conversions in SQL Server convert (varchar, GETDATE (), 120)

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.