SQL DateDiff advanced usage?

前端 未结 6 1535
慢半拍i
慢半拍i 2020-12-19 19:26

I need to calculate the DateDiff (hours) between two dates, but only during business-hours (8:30 - 16:00, no weekends). This result will then be put into the Reaction_Time c

6条回答
  •  清酒与你
    2020-12-19 19:50

    Use this code : to find out weekend in between dates

     (
        DATEDIFF(dd, open_date, zassignment_date) + 1 
        - ( (DATEDIFF(dd, open_date, zassignment_date) + 1) 
        -(DATEDIFF(wk, open_date, zassignment_date) * 2) 
        -(CASE WHEN DATENAME(dw,  open_date) = 'Sunday' THEN 1 ELSE 0 END) 
        -(CASE WHEN DATENAME(dw, zassignment_date) = 'Saturday' THEN 1 ELSE 0 END) )) wk_end 
    

提交回复
热议问题