以绝对格式获取两个日期之间的差异。 [英] Get difference between two dates in absolute format.
本文介绍了以绝对格式获取两个日期之间的差异。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我试图运行这个查询,但它对我不起作用。
@ StartDt NVARCHAR( 25 ),
@Period INT
UPDATE CROS_L SET DUE5 = bal_amt WHERE ABS(CONVERT(DATETIME,@ StartDt, 103 ) - due_date)> = @Period AND due_date IS NOT NULL;
异常:
隐式转换来自数据类型 datetime 到 float 不允许。 使用 CONVERT function 运行此查询。
需要建议
最好的问候
解决方案
@ StartDt NVARCHAR ( 25 ),
@ Period INT
更新 CROS_L SET DUE5 = bal_amt WHERE ABS( datediff(day, CONVERT ( DATETIME , @ StartDt , 103 ),due_date))> = @ Period AND due_date IS NOT NULL ;
快乐编码!
:)
DECLARE
@ StartDt DATETIME = ' 2013-03-11 11:22:52.053'
, @ Period INT = 1
, @ due_date DATETIME = ' 2013-03-18 11: 22:52.053'
- 这将更新为它将返回7作为DATEDIFF,大于期间,此处为1
UPDATE CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D, @ StartDt , @ due_date )> = @ Period AND @ due_date IS NOT NULL 跨度>;
SET @ Period = 10
- 这不会更新,因为它将返回7作为DATEDIFF,其不大于10岁以上的期间
更新 CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D, @ StartDt , @ due_date )> = @ Period AND @ due_date IS NOT NULL 跨度>;
Hello There,
I tried to run this query but it didn''t work for me.
@StartDt NVARCHAR(25),
@Period INT
UPDATE CROS_L SET DUE5 = bal_amt WHERE ABS(CONVERT(DATETIME,@StartDt,103)- due_date) >= @Period AND due_date IS NOT NULL;
Exception:
Implicit conversion from data type datetime to float is not allowed. Use the CONVERT function to run this query.
Need Suggestion
Best Regards
解决方案
@StartDt NVARCHAR(25), @Period INT UPDATE CROS_L SET DUE5 = bal_amt WHERE ABS(datediff(day,CONVERT(DATETIME,@StartDt,103), due_date)) >= @Period AND due_date IS NOT NULL;
Happy Coding!
:)
DECLARE @StartDt DATETIME = '2013-03-11 11:22:52.053' ,@Period INT = 1 ,@due_date DATETIME = '2013-03-18 11:22:52.053' --This will Update as it will return 7 as DATEDIFF which is greater than period which is 1 over here UPDATE CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D,@StartDt,@due_date) >= @Period AND @due_date IS NOT NULL; SET @Period = 10 --This will not Update as it will return 7 as DATEDIFF which is not greater than period which is 10 over here UPDATE CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D,@StartDt,@due_date) >= @Period AND @due_date IS NOT NULL;
这篇关于以绝对格式获取两个日期之间的差异。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文