Python: Number of the Week in a Month

前端 未结 9 595
庸人自扰
庸人自扰 2020-12-03 18:26

When specifying a date:

datetime.datetime(2011, 8, 15)

How can i get to know that this is the third week of the month?

What if I wa

9条回答
  •  独厮守ぢ
    2020-12-03 18:43

    testdate = datetime.datetime(2011, 2, 28)
    weekofmonth = (testdate.day+7-1)/7
    

    In general to find the ceiling of division: ceiling of (x/y) = (x+y-1)/y

提交回复
热议问题