sql-server - "Adding a value to a ' 日期时间 ' column caused an overflow."

标签 sql-server function tsql date sql-server-2008-r2

MSDN中明确指出:

The date argument cannot be incremented to a value outside the range of its data type. In the following statements, the number value that is added to the date value exceeds the range of the date data type. The following error message is returned: "Adding a value to a 'datetime' column caused overflow."

示例:

SELECT DATEADD(year,2147483647, '2006-07-31');
SELECT DATEADD(year,-2147483647, '2006-07-31');

这会导致错误:

"Adding a value to a 'datetime' column caused overflow."

这看起来是对的。但为什么我执行此 SQL 语句时遇到相同的错误:

SELECT DATEDIFF(YY,'1013-12-12',DATEADD(YY,-300,getdate()))

更具体且唯一:

SELECT DATEADD(YY,-300,getdate())

最佳答案

First google result for 'sql datetime range' 。 1753 年 1 月 1 日。这是你的下限。

对添加的问题的评论this trivia关于这个下限的起源。

关于sql-server - "Adding a value to a ' 日期时间 ' column caused an overflow.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9401643/

相关文章:

SQL Server 从引用索引表的非索引 View 中选择

php - 将返回的字符串传递给另一个字符串并在 if 语句中使用它

sql-server - 使用匿名数据更新大型(280M 行)表

sql - 使用 2016 年之前的 tsql 功能解压缩 gzip 字段

c# - EntityFramework - 查询执行时间取决于选择顺序?

.net - .NET 中通过 WMI 的数据库大小

Java 连接到 SQL Server

c# - 在 C# 中处理 UTC 时间?

将字符串源复制到目标中,然后在 C 中追加一个字符

c# - 我如何在 C# 中获得特定运算符的函数?