I want to calculate the difference between the two dates but want to exclude the weekends from it . Below is the format of dates :
CreateDate - 2017-08-29 1
With datetime module:
datetime
import datetime d1 = datetime.datetime.strptime('2017-08-29 10:47:00', '%Y-%m-%d %H:%M:%S') d2 = datetime.datetime.strptime('2017-09-23 16:56:00', '%Y-%m-%d %H:%M:%S') delta = (d2 - d1).days diff_weekdays = delta - (delta // 7) * 2 print(diff_weekdays) # 19