简体   繁体   English

如何使用 python 计算截止日期之间的工作日?

[英]How to calculate working days using python between to dates?

I did find this solution click here to see article but still not exactly what I was looking for.我确实找到了这个解决方案,点击这里查看文章,但仍然不是我想要的。 The solution calculates all the days between 2 dates, including weekends.该解决方案计算 2 个日期之间的所有天数,包括周末。 So, is there a solution that excludes the weekends in the calculation?那么,有没有在计算中排除周末的解决方案呢?

So, what I did is take that solution and expand it this way:所以,我所做的就是采用该解决方案并以这种方式扩展它:

crtD = datetime.datetime.strptime(pd.loc[x,'createDate'], '%m/%d/%Y') # start date
tdyD = datetime.datetime.today() # end date
dayx = tdyD - crtD # number of days between start and end date. Includes weekends
wkds = dayx.days + 1 # eliminates time stamp and just leaves the number of days and adds 1 day
wkns = round(wkds/7,0) # divides the number of days by seven and rounds the result to the nearest integer
networkdays = int(wkds - wkns) - 1
print(networkdays)

I embedded these lines of code in a for loop.我将这些代码行嵌入到一个for循环中。 Hope this helps.希望这可以帮助。 If you have a solution to include Holidays, please post it here.如果您有包含假期的解决方案,请在此处发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM