我有两个约会,例如:
import datetime
start_date = datetime.datetime.today().date()
end_date = start_date + datetime.timedelta(days=30)
现在考虑我有个假期tomorrow
,如何确定工作日总数。工作日是排除saturday and sunday
的日子。
谢谢。
答案 0 :(得分:1)
使用datetime
模块。
例如:
import datetime
start_date = datetime.datetime.today().date()
end_day = 30
bDays = sum(1 for day in range(1, end_day + 1) if (start_date + datetime.timedelta(days=day)).weekday() not in [5, 6] )
print(bDays)
输出:
22
答案 1 :(得分:0)
您可以尝试以下方法吗?
import datetime
import numpy as np
start_date = datetime.datetime.today().date()
end_date = start_date + datetime.timedelta(days=30)
holidays = [start_date + datetime.timedelta(days=1)]
print(np.busday_count(start_date, end_date, holidays=holidays))