#datetime
1 messages · Page 1 of 1 (latest)
pretty sure since their both time objects u can just sutract the 2
Probably best to not convert them to string right away.
def diff_in_minutes(start: datetime.datetime, end: datetime.datetime) -> float:
return (end-start).total_seconds() / 60
Pass the start and end to a function and have it return the float value of minutes between the two times.
example:
import datetime
def diff_in_minutes(start: datetime.datetime, end: datetime.datetime) -> float:
return (end-start).total_seconds() / 60
start = datetime.datetime.now()
end = datetime.datetime.now() + datetime.timedelta(minutes=5, seconds=40)
minutes = diff_in_minutes(start, end)
print(minutes)
# 5.666666666666667
I am adding start & end to the database because they are in different classes and I need to add their difference to the database too
I'd argue that you don't need to store the difference at all. Store the start and end as timestamps, then calculate the difference when you need it.
I'll try, thanks