如何确定两个日期之间有多少个星期一

时间:2016-09-29 03:01:44

标签: python-2.7 date odoo-8

我正在开发一个Odoo工资单模块,我遇到了问题。

委内瑞拉存在名为“社会保障”的薪资规则,其公式为:

(((Wage * 12)/ 52)* 0.04)*日期之间的星期一

有没有办法计算Python27中两个日期之间的星期一数量?

1 个答案:

答案 0 :(得分:0)

def num_mondays_between( start, end):

   num_weeks, remainder = divmod( (end-start).days, 7)

   if start.weekday() == 0:  # start is monday
       # one monday for each week between plus start
       return num_weeks + 1  
   elif ( 7 - start.weekday() ) <= remainder:
       # the closer start is to a monday, a smaller remainder has a monday
       return num_weeks + 1
   else:
       return num_weeks