Business Days calculation

前端 未结 3 1155
悲哀的现实
悲哀的现实 2020-12-22 01:11

I have a query where I am calculating total days between two days including start and end date by the following SQL query. If the end date is not null, then end date is cons

3条回答
  •  一向
    一向 (楼主)
    2020-12-22 02:12

    try this

    SELECT  DateDiff(day,DateADD(day,-1,StartDate),ISNULL(EndDate,getDate())) - 
    ( CASE WHEN DATENAME(dw, StartDate) = 'Sunday' OR 
    DATENAME(dw,ISNULL(EndDate,getDate())) = 'Sunday' THEN 1 ELSE 0 END)
    - ( CASE WHEN DATENAME(dw, StartDate) = 'Saturday' OR 
         DATENAME(dw,ISNULL(EndDate,getDate())) = 'Saturday' THEN 1 ELSE 0 END)
    numberOfDays         
    FROM  
    

提交回复
热议问题