How do I subtract two times to get a duration in Python?
I have tried the following code below using datetime.
Input for start time= 20-07-2020 11:00:00
Input for stop time= 20-07-2020 13:30:00
The output I would like is 2.5 hours or 2 hours 30 minutes
from datetime import datetime
print("Enter 11:00 13:30 for a task starting at 11am and ending at 1:30 pm.")
start=str(input("Enter the start time:"))
stop=str(input("Enter the stop time:"))
format_date= "%d-%m-%Y %H:%M:%S"
duration=datetime.strptime(start,format_date)-datetime.strptime(stop,format_date)
duration
Task1_start=datetime.strptime(start,format_date)
Task1_stop=datetime.strptime(stop,format_date)
print(f'Start:{Task1_start}, Stop:{Task1_stop}')