Django Logbook Timefield() subtraction for total time

118 views Asked by At

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!

1

There are 1 answers

3
Arvind Kumar On

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