Datetime Python - Next Business Day

后端 未结 5 1576
旧巷少年郎
旧巷少年郎 2020-12-30 06:57

Two related issues: (1) All of the data I work with have weekday dates attached. At various points, I need to know what the next weekday is. I\'ve written something like the

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 07:31

    another way without ifs would be:

    def next_wk_day():
        date_today = datetime.datetime.today()
        shift = 1 + ((date_today.weekday()//4)*(6-date_today.weekday()))
        return(date_today+shift)
    

    which would also work in case you are doing it on a Saturday or Sunday.

提交回复
热议问题