SQL 什么是日期时间2?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/655745/
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
What is datetime2?
提问by Glenn
I′ve got this in a INSERT statment to MSSQL 2008
我在 MSSQL 2008 的 INSERT 语句中得到了这个
System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
System.Data.SqlClient.SqlException:将 datetime2 数据类型转换为 datetime 数据类型导致值超出范围。
采纳答案by Cantillon
Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.
定义与基于 24 小时制的一天中的时间相结合的日期。datetime2 可以被认为是现有日期时间类型的扩展,它具有更大的日期范围、更大的默认小数精度和可选的用户指定精度。
回答by Walden Leverich
SQLServer's datetime datatype is a much smaller range of allowed values than .net datetime datatype. SQLServer's datetime type basically supports the gregorian calendar, so the smallest value you can have is 1/1/1753. In 2008 SQLServer added a datetime2 datatype that supports back to year 1 (there was no year 0). Sounds like you're trying to insert a datetime value that's before 1/1/1753 into a datetime (not datetime2) SQLServer column
SQLServer 的 datetime 数据类型的允许值范围比 .net datetime 数据类型小得多。SQLServer 的日期时间类型基本上支持公历,因此您可以拥有的最小值是 1/1/1753。2008 年,SQLServer 添加了一个 datetime2 数据类型,支持回溯到第 1 年(没有第 0 年)。听起来您正在尝试将 1/1/1753 之前的日期时间值插入到日期时间(不是 datetime2)SQLServer 列中
回答by Paulo Guedes
From technet:
从的TechNet:
Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.
定义与基于 24 小时制的一天中的时间相结合的日期。datetime2 可以被认为是现有日期时间类型的扩展,它具有更大的日期范围、更大的默认小数精度和可选的用户指定精度。
I had to check because I thought datetime2
had some relation with varchar2
. Apparently, no relation at all.
我不得不检查,因为我认为datetime2
与varchar2
. 显然,根本没有关系。
Put your code so we can guess what caused the problem.
放置您的代码,以便我们猜测导致问题的原因。
回答by marc_s
Could it be that your database table has a "DATETIME" or "SMALLDATETIME" column and you're trying to insert an out-of-range date?? DATETIME covers 1753-1-1 through 9999-12-31, while SMALLDATETIME covers 1900-1-1 through 2079-6-6 only.
可能是您的数据库表有一个“DATETIME”或“SMALLDATETIME”列,而您正试图插入一个超出范围的日期??DATETIME 涵盖 1753-1-1 到 9999-12-31,而 SALLDATETIME 仅涵盖 1900-1-1 到 2079-6-6。
The new SQL Server 2008 DATETIME2 data type will cover 0001-1-1 through 9999-12-31.
新的 SQL Server 2008 DATETIME2 数据类型将涵盖 0001-1-1 到 9999-12-31。
Marc
马克
回答by Anton Swanevelder
I got this error when my database column was created as NOT NULL and I specifically specified a Nullable = true on my DateTime Property in my ADO.Entity framework EntityType.
当我的数据库列被创建为 NOT NULL 并且我在我的 ADO.Entity 框架 EntityType 的 DateTime 属性上特别指定了一个 Nullable = true 时,我收到了这个错误。
To fix it I make the Nullable property = (None)
为了修复它,我使 Nullable 属性 = (None)