DATEDIFF interval=ms的用法

时间:2021-08-22 23:30:02

datediff(ms,@CurrDateTime,@Date)>0

当上面的日期超过24天,用上面的sql会有问题

要修改成如下:

(CONVERT(VARCHAR,@CurrDateTime,111)=CONVERT(VARCHAR,@Date,111) AND datediff(ms,@CurrDateTime,@Date)>0)

OR (CONVERT(VARCHAR,@CurrDateTime,111)<>CONVERT(VARCHAR,@Date,111) AND datediff(d,@CurrDateTime,@Date)>0))

For your references:

http://technet.microsoft.com/en-us/library/aa258269(v=sql.80).aspx

“DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years.”