简体   繁体   English

将表达式转换为数据类型日期时间的算术溢出错误

[英]Arithmetic overflow error converting expression to data type date time

I am trying to get days difference between 2 days and I am getting below error.我试图获得 2 天之间的天数差异,但我得到了低于错误的结果。 Could any one please help任何人都可以帮忙

CONVERT(DECIMAL,((dbo.convertToUnixTime(GETDATE())-p.CREATEDDATE)))

Msg 8115, Level 16, State 2, Line 79 Msg 8115, Level 16, State 2, Line 79

Arithmetic overflow error converting expression to data type datetime.将表达式转换为数据类型日期时间时出现算术溢出错误。

使用日期函数:

SELECT DATEDIFF(day,GETDATE(),p.CREATEDATE)

datediff() always return an integer value, expressed in the unit your are giving as first argument. datediff()总是返回一个整数值,以您作为第一个参数给出的单位表示。

If you want something accurate, you can compute the date difference in seconds, then use artithmetics to convert to a number of days:如果你想要一些准确的东西,你可以计算以秒为单位的日期差异,然后使用算术转换为天数:

datediff(second, p.createdate, getdate()) / 60.0 / 60 / 24

If you want fractional days, then you can take the difference in another unit, say seconds, and divide:如果你想要小数天,那么你可以用另一个单位来计算差异,比如秒,然后除以:

SELECT DATEDIFF(second, p.CREATEDATE, GETDATE()) / (24.0 * 60 * 60)

Note that for DATEDIFF() the older date goes first.请注意,对于DATEDIFF() ,较旧的日期排在第一位。 I assume p.CREATEDATE is in the past and you want a positive number.我假设p.CREATEDATE是过去的并且你想要一个正数。

If you are dealing with dates far in the past or the future, you might want to use minute rather than second or alternatively DATEDIFF_BIG() .如果您正在处理过去或将来很远的日期,您可能希望使用minute而不是secondDATEDIFF_BIG()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 **偶尔**将表达式转换为数据类型int的算术溢出错误 - **Occasional** Arithmetic overflow error converting expression to data type int 将表达式转换为数据类型money 的算术溢出错误 - Arithmetic overflow error converting expression to data type money “将表达式转换为数据类型 nvarchar 时出现算术溢出错误。” - "Arithmetic overflow error converting expression to data type nvarchar." 将表达式转换为数据类型nvarchar的SQL算术溢出错误 - SQL Arithmetic overflow error converting expression to data type nvarchar 将表达式转换为数据类型float的算术溢出错误 - Arithmetic overflow error converting expression to data type float 算术溢出错误将表达式转换为日期时间为'#N / A'的数据类型 - Arithmetic overflow error converting expression to data type datetime with value '#N/A' SQL Server算术溢出错误将表达式转换为数据类型datetime - SQL Server Arithmetic overflow error converting expression to data type datetime SQL Server:将表达式转换为数据类型int的算术溢出错误 - SQL Server : Arithmetic overflow error converting expression to data type int 将表达式转换为数据类型int SQL Server的算术溢出错误 - Arithmetic overflow error converting expression to data type int SQL Server 将表达式转换为数据类型 bigint 的算术溢出错误 - Arithmetic overflow error converting expression to data type bigint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM