0

I am trying to determine the amount of days between updates on a ticket in zendesk, excluding weekends. I have been able to determine the difference between updates, but it doesnt take into account weekends. I want to determine if the user has updated their ticket within 3 days, excluding weekends, then close the ticket if it has been over 3 days. This is what I have:

updated_time = updated_time[0:10:1]
time_now = str(datetime.datetime.now())
time_now = time_now[0:10:1]
updated_time = dateutil.parser.parse(updated_time)
time_now = dateutil.parser.parse(time_now)
date_to_close = datetime.timedelta(days=3)
please_close = time_now - updated_time

My problem is because it doesnt distinguish between weekdays and weekends, it will automatically close the ticket on Monday if no one has responded over the weekend, which I would not like to count. I've been looking at the isoweekday() but its not really giving me what I need. I was thinking about trying to assign the ticket to a variable and assigning it a number, then increase that number by days without an update, that way it would not count the specific date but rather the number of days in between, but not sure how to do this or if it would even work.

Does anyone have an idea how to count the difference between days while excluding weekends? Is this possible?

Jon
  • 11
  • 2
  • It is absolutely possible. – Scott Hunter Dec 08 '20 at 18:44
  • I don't see why `weekday()` or `isoweekday()` won't work. They sound perfectly suited to this issue. You explained that you're "looking at it" but "it's not really giving you what you need", but neither of those explanations actually is helpful, or shows what you've tried or what issues you ran into. – Random Davis Dec 08 '20 at 18:49
  • You could use the `weekday()` function from the `calendar` module: https://docs.python.org/3/library/calendar.html – Arne Dec 08 '20 at 18:49
  • Sorry for the lack of clarity. So what is happening now is it is using the numerical value of the date then decides if it has been 3 days, if it has then it closes the ticket. The problem is, if I have a ticket created on Fri Dec. 4th, when the script runs on Mon, it will close the ticket because the date would be Dec 7th, which is over 3 days. I'm trying to get it to ignore the weekend days. It's my understanding that the weekday() gives a 0-6 int. For the above example, that Fri Dec 4th would be 5, then Mon Dec 7th would be 0. Im not sure how to ignore Sat/Sun and start back on Mon. – Jon Dec 09 '20 at 20:09

2 Answers2

0

If you already know how many days (of any kind), that value must be equal to 7w+x (that is, w full weeks and x days of the remaining partial week). You know that there are 5 weekdays in every full week; that just leaves figuring out how many of the remaining x days are weekdays, which you can determine from how many days until the first weekend and comparing that to x.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
0

Ok, after a lot of digging and reaching out to another python programmer I know, he pointed me to the numpy function busday_count(). This does the calculation that I need. The reference is: Python - Exclude weekends between two Dates

Thanks very much for everyone's answers!

Jon
  • 11
  • 2