How to calculate next Friday?

前端 未结 7 1961
失恋的感觉
失恋的感觉 2020-12-13 13:34

How can I calculate the date of the next Friday?

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 14:08

    import datetime 
    def next_fri_13(start_date):
            next_friday = start_date + datetime.timedelta(((4 - today.weekday()) % 7))
            while True:
                if next_friday.day==13:
                    thirteen_friday = next_friday
                    break
                else:
                    next_date = next_friday + datetime.timedelta(days=1)
                    next_friday = next_date + datetime.timedelta(((4 -next_date.weekday())% 7))
            return thirteen_friday
    
        r = next_fri_13(datetime.date(2020, 2, 11)) print(r)
    

提交回复
热议问题