0

I would like to write a function that calculate working business hours in python, to do that I don't like to define a class and use python ready function to calculate.

I tried with following code but this is not what I wanted. do you have any suggestion?

import datetime

start_time = datetime.datetime(2019, 12, 1, 22, 45, 25)
end_time = datetime.datetime(2019, 12, 7, 10, 00, 00)

hours = BusinessHours(start_time, end_time, worktiming=[9, 18], weekends=[6, 7], holidayfile=None)
print(hours.gethours())

I would like to have an input as of "2019-12-01 09:30:00" and "2019-12-07 12:15:00" and the output should be 40 hours

user14269252
  • 412
  • 4
  • 15
  • Did you try [Timedelta](https://docs.python.org/3/library/datetime.html#datetime.timedelta) ? – Alex J Sep 12 '22 at 12:33
  • Timedelta is not what I want, I like to write a function for calculation – user14269252 Sep 12 '22 at 12:36
  • Does this answer your question? [Business Hours Between Two Dates in Pandas Dataframe (including holidays)](https://stackoverflow.com/questions/46899627/business-hours-between-two-dates-in-pandas-dataframe-including-holidays) – Laurent Sep 17 '22 at 16:04

0 Answers0