T-SQL time format CONVERT (), t-sqlconvertFunctionReturns the expression converted to the provided data type.Syntax
CONVERT (data type, expression [, format-style])
Example:
convert(varchar(10),getdate(),112)
Parameters
The data type expression
First, review the syntax format of CONVERT (): convert ([length], [, Style])
Second, here pay attention to the meaning of style: style is the conversion of datatime and smalldatetime data to a string by the SQL Server system provided by the
The CONVERT function converts the time to a new type of common format , which makes it easy to queryCONVERT (Type,expression,style)Type: For example: varchar (10) database string types, size can be self-determinedExpression: A field representing
http://www.w3school.com.cn/sql/func_convert.asp Definition and usageThe 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.GrammarCONVERT
Cast (expression as data_type (length))Convert (data_type (length), expression, style) // If lengthis not specified, the default is 30 characters. data_type (length) Specifies the target data type (with optional lengths). The data_to_be_converted
CONVERT (varchar (10), field name, conversion format)convert (nvarchar, count_time,121) convert is a date conversion function, typically in the time type (Datetime,smalldatetime) and the string type (Nchar,nvarchar,char , varchar) 3 parameters of
DateTime is the most commonly used date type in SQL.Storage size: 8 bytes;Date range: 1753-01-01 to 9999-12-31;Accuracy: 3.33 ms;Common Date function getdate () Gets the current date of the systemSelect GETDATE ()DatePart (Part,dtvalue) Gets the
Convert a date format using the CONVERT function in SQL Server2008-01-23 15:47
Convert date format with convert function in SQL Server 2008-01-15 convert date format with convert function in 15:51sqlserverThe default date field for the
SQL Server Date functionThe following table lists the most important built-in date functions in SQL Server:
function
Description
GETDATE ()
Returns the current date and time
DATEPART ()
function
Description
GETDATE ()
Returns the current date and time
DATEPART ()
Returns a separate part of the date/time
DATEADD ()
Add or subtract a specified time interval in a date
the list of styles that can be applied are:
SQL style id
SQL style
example
0 or 100
Mon dd yyyy hh: miam (or pm)
Jan 15 2008 pm
101
Mm/DD/yy
01/15/2008
102
YY. Mm. dd
Add convert conversion to the query... Convert (varchar (10), field name, conversion format) such as selectuser_id, convert (varchar (10), date, 11) asdatefromtb_user conversion format: 0 or 100 monthddyyyyhh: miAMPM1mmddyy2yy. mm. dd3ddmmyy4dd. mm.
1. Delete the first character of each line of the file.Sed ' s/.//' install.logSed-n ' S/^.//GP '/etc/passwd Sed-nr ' s/(.) (. *)/\2/p '/etc/passwd2. Delete the second character of each line of the file.Sed ' S/.//2 ' install.logSed ' s/(.) (.) (. *)
This style is generally used only when the time type (datetime, smalldatetime) and string type (nchar, nvarchar, char, varchar) are converted to each other.
This style is generally used only when the time type (datetime, smalldatetime) and string
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.