I wrote a program to compute the hours I've worked but at the end, it returns the value as a time.
EX: I worked from 11:45 to 4:30.
My program returns 4:45 I would like it to return 4.75.
How do I convert this?
I am using the following code:
import datetime as dt
from datetime import timedelta
start =(input("Enter start time: " ))
end =(input("Enter start time: " ))
start_dt = dt.datetime.strptime(start, '%H:%M')
end_dt = dt.datetime.strptime(end, '%H:%M')
time =(end_dt - start_dt)
if time.days < 0:
time=timedelta(days=0,seconds=time.seconds,microseconds=time.microseconds)
time= str(time)
time2=dt.datetime.strptime(time, '%H:%M:%S')
off_set=dt.datetime.strptime('12:00:00', '%H:%M:%S')
time= time2 - off_set
print (time)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…