[英]Rounding up DATEDIFF, TSQL
I tried using CEILING to round up a DATEDIFF value but still got zero: 我尝试使用CEILING舍入DATEDIFF值,但仍然为零:
SELECT (CEILING(DATEDIFF(DAY, '2016-04-02T04:59:59', '2016-04-02T05:59:59')))
Is it possible to round up DATEDIFF? 是否可以舍入DATEDIFF?
DATEDIFF()
returns 0
when using day
if the two dates are the same day. DATEDIFF()
返回0
使用的时候day
如果这两个日期是同一天。 You need to use a smaller time increment and divide the result of the DATEDIFF()
, Hour and 24, Minute and 1440, Second and 86,400, etc: 您需要使用较小的时间增量并将DATEDIFF()
的结果除以Hour和24,Minute和1440,Second和86,400,等等:
SELECT CEILING(DATEDIFF(Second, '2016-04-02T04:59:59', '2016-04-02T05:59:59')/(24.0*60*60))
Note: Divide the DATEDIFF()
result by a decimal value otherwise it will return an integer. 注意:将DATEDIFF()
结果除以十进制值,否则将返回整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.