![](/img/trans.png)
[英]How to calculate difference in hours (decimal) between two dates in SQL Server?
[英]In tableau, how to calculate login hours between two dates date wise?
例如,我的登錄時間是7am
到11pm
。 您想按日期計算18/10/2019 5:30:40
和21/10/2019 14:05:15
之間的處理時間。 考慮最終結果中的所有假期和周末。
Output 我們應該得到上面的例子:
18/10/2019 16 hrs
19/10/2019 16 hrs
20/10/2019 16 hrs
21/10/2019 7.0875 hrs
從早上 7 點到晚上 11 點的登錄時間意味着 16 小時工作日:
IF Datediff('day',[LogInTime],[LogOffTime])=0 Then
(IF Datepart('hour',[LogOffTime])>23 then 23 else Datepart('hour',[LogOffTime]) end)-
(IF Datepart('hour',[LogInTime])<7 then 7 else Datepart('hour',[LogInTime]) end)
Else
Datediff('day',[LogInTime],[LogOffTime])*16 +
(IF Datepart('hour',[LogOffTime])>23 then 23 else Datepart('hour',[LogOffTime]) end)-
(IF Datepart('hour',[LogInTime])<7 then 7 else Datepart('hour',[LogInTime]) end)
End
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.