I'm trying to automate documenting my worktimes and need a way to get the duration between the starting and ending time. During my research I came upon this question which seemed to provide a solution to my problem.
However, when trying to get the duration between "11:30" and "12:30" the datetime.time() method returns "00:00:00" and I have no idea why.
This is the code I'm using.
from datetime import datetime, timedelta
from time import strptime
start = strptime("11:30", "%H:%M")
stop = strptime("12:30", "%H:%M")
start_dt = datetime(100, 1, 1, start.tm_hour, start.tm_min)
duration = start_dt + timedelta(hours=stop.tm_hour,
minutes=stop.tm_min,
seconds=0)
print(duration.time())
This is my expected (desired) output:
01:00:00
This is the actual output I'm getting:
00:00:00
I was wondering whether it had something to do with the time.strptime() method I'm using to get hour and minute values so I tried this as well:
from datetime import datetime, timedelta
start_dt = datetime(100, 1, 1, 11, 30)
duration = start_dt + timedelta(hours=12,
minutes=30,
seconds=0)
print(duration.time())
The output remains the same. Does anyone know why? I'm completely at a loss. Any help would be appreciated.