How to get the next working day, excluding weekends and holidays

前端 未结 5 1020
攒了一身酷
攒了一身酷 2020-12-16 12:47

I have a requirement where I need to work on a date field, so the requirement is some thing like this

I will call the field as minimum possible date

5条回答
  •  太阳男子
    2020-12-16 13:02

    I had similar requirement in my project , and i retrieved by using SQl Server. If you can do in SQL server , we have very simple query which returns the next business day.

    DECLARE @dt datetime='20150113' 
    SELECT DATEADD(dd,CASE WHEN DATEDIFF(dd,0,@dt)%7 > 3 THEN 7-DATEDIFF(dd,0,@dt)%7 ELSE 1 END,@dt)
    

    Explanation :
    Always base date is '1900 jan 1 st ' As per DB
    19000101 --> Monday --> -- So result is THEN VALUE =1 day
    19000102 --> Tuesday --> -- So result is THEN VALUE =1 day
    19000103 --> Wednesday --> -- So result is THEN VALUE =1 day
    19000104 --> Thursday --> -- So result is THEN VALUE =1 day
    19000105 --> Friday --> -- So result is 7-@number = 3 days
    19000106 --> Saturday --> -- So result is 7-@number =2 days
    19000107 --> Sunday --> -- So result is 7-@number =1 day

提交回复
热议问题