Reputation: 1
i have been trying to figure how how do I do a simple subtraction between two time fields and show the total time on the admin page as well for confirmation before saving. example would be actual time of arrival - actual time of departure = total flight time
atd = models.TimeField(null=True, default='00:00:00') ata = models.TimeField(null=True, default='00:00:00')
trying to get atd - ata to get the total flight time, how do i do this in django.
thanks for your help!
Upvotes: 0
Views: 120
Reputation: 973
You can try the following
import datetime
time1 = datetime.datetime.strptime(atd,'%H:%M:%S')
time2 = datetime.datetime.strptime(ata,'%H:%M:%S')
difference = time2-time1
Upvotes: 0