6π
β
>>> import datetime
>>> time1 = datetime.datetime.strptime("6:30",'%H:%M')
>>> time2 = datetime.datetime.strptime("7:30",'%H:%M')
>>> difference = time2-time1
>>> difference
datetime.timedelta(0, 3600)
>>> difference.seconds
3600
>>> "{:0>8}".format(datetime.timedelta(seconds=difference.seconds))
'01:00:00'
>>> "{:0>8}".format(datetime.timedelta(seconds=666777))
'7 days, 17:12:57'
π€Rizwan Mumtaz
0π
>>> from datetime import datetime
>>> s1 = "06:30"
>>> s2 = "07:30"
>>> timeformat = "%I:%M"
>>> delta = datetime.strptime(s2, timeformat) - datetime.strptime(s1, timeformat)
>>> delta
datetime.timedelta(0, 3600)
>>> delta.seconds
3600
delta
is the time difference. You can check the value and convert accordingly.
π€Barun Sharma
- [Django]-Gunicorn with unix socket not working gives 502 bad gateway
- [Django]-How to save foreign keys using django-rest-framework
- [Django]-Django create profile for user signal
Source:stackexchange.com