我正在使用datediff
来区分两个日期时间:
DATEDIFF(hh, CAST(CAST(dbo.QuickLabDump.[Date Entered] AS DATE) AS DATETIME)
+ CAST(dbo.QuickLabDump.[Time Entered] AS TIME),
CAST(CAST(dbo.QuickLabDump.[Date Completed] AS DATE) AS DATETIME)
+ CAST(dbo.QuickLabDump.[Time Completed] AS TIME)) AS [Hours TurnAround]
我不明白我从这句话中得到的行为,但我需要的是>= :30, round up, if not, round down,
问题如何在不到30分钟时将其向下舍入,如果大于或等于30分钟则将时间向上舍入?
答案 0 :(得分:3)
您应该在几分钟内计算DATEDIFF
,然后执行ROUND
:
ROUND(CAST(DATEDIFF(MINUTES, CAST(CAST(dbo.QuickLabDump.[Date Entered] AS DATE) AS DATETIME)
+ CAST(dbo.QuickLabDump.[Time Entered] AS TIME), CAST(CAST(dbo.QuickLabDump.[Date Completed] AS DATE) AS DATETIME)
+ CAST(dbo.QuickLabDump.[Time Completed] AS TIME)) AS FLOAT)/60,0) AS [Hours TurnAround]