SQL SELECT CONVERT(VARCHAR(10), GETDATE(), 110) 这里的110是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16229915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 15:00:36  来源:igfitidea点击:

SELECT CONVERT(VARCHAR(10), GETDATE(), 110) what is the meaning of 110 here?

sqldatecastinggetdate

提问by Gaurav

When we convert or cast date in sql, see below sql code

当我们在 sql 中转换或转换日期时,请参阅下面的 sql 代码

SELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY] 

it works fine, I just want to know the meaning of 110 in above code. what it does actually, sometimes we use 102, 112 etc. what is the use of that number.

它工作正常,我只想知道上面代码中 110 的含义。它实际上做了什么,有时我们使用 102、112 等。这个数字有什么用。

回答by hims056

That number indicates Date and Time Styles

该数字表示日期和时间样式

You need to look at CAST and CONVERT (Transact-SQL). Here you can find the meaning of all these Date and Time Styles.

您需要查看CAST 和 CONVERT (Transact-SQL)。在这里您可以找到所有这些日期和时间样式的含义。

Styles with century (e.g. 100, 101 etc) means year will come in yyyyformat. While styles without century (e.g. 1,7,10) means year will come in yyformat.

带有世纪的样式(例如 100、101 等)意味着年份将以yyyy格式出现。而没有世纪的样式(例如 1,7,10)意味着年份将以yy格式出现。

You can also refer to SQL Server Date Formats. Here you can find all date formats with examples.

您还可以参考SQL Server 日期格式。在这里您可以找到所有带有示例的日期格式。

回答by John Woo

110is the Style value for the date format.

110是日期格式的样式值。

TSQL Date and Time Styles

TSQL 日期和时间样式

回答by Vinayak Pahalwan

When you convert expressions from one type to another, in many cases there will be a need within a stored procedure or other routine to convert data from a datetime type to a varchar type. The Convert functionis used for such things. The CONVERT()function can be used to display date/time data in various formats.

当您将表达式从一种类型转换为另一种类型时,在许多情况下,在存储过程或其他例程中需要将数据从日期时间类型转换为 varchar 类型。将Convert function用于这样的事情。该CONVERT()函数可用于以各种格式显示日期/时间数据。

Syntax

句法

CONVERT(data_type(length), expression, style)

Style- style values for datetime or smalldatetime conversion to character data. Add 100 to a style value to get a four-place year that includes the century (yyyy).

样式- datetime 或 smalldatetime 转换为字符数据的样式值。将 100 添加到样式值以获得包含世纪 (yyyy) 的四位年份。

Example 1

示例 1

take a style value 108 which defines the following format:

取一个样式值 108,它定义了以下格式:

hh:mm:ss

时:分:秒

Now use the above style in the following query:

现在在以下查询中使用上述样式:

select convert(varchar(20),GETDATE(),108) 

Example 2

示例 2

we use the style value 107 which defines the following format:

我们使用样式值 107,它定义了以下格式:

Mon dd, yy

周一,年

Now use that style in the following query:

现在在以下查询中使用该样式:

select convert(varchar(20),GETDATE(),107) 

Similarly

相似地

style-106 for Day,Month,Year (26 Sep 2013)
style-6 for Day, Month, Year (26 Sep 13)
style-113 for Day,Month,Year, Timestamp (26 Sep 2013 14:11:53:300)

回答by Michael Wong

10 = mm-dd-yy 110 = mm-dd-yyyy

10 = 毫米-日-年 110 = 毫米-日-年

SQL Server CONVERT() Function

SQL Server CONVERT() 函数