This is a very noobish question, so I apologize in advance!
I have two time stamps for start and end of the event. They are stored in as datetime.datetime in UTC. What I need to do is figure out the duration of the event.
I tried subtracting one from the other, but receive error:
Traceback (most recent call last): 02. File '/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py', line 509, in __call__ 03. handler.post(*groups) 04. File '/base/data/home/apps/.../3.340324527833140591/main.py', line 441, in post 05. call_record.Duration = call_record.CallStartTime - call_record.CallEndTime 06. File '/base/python_lib/versions/1/google/appengine/ext/db/__init__.py', line 472, in __set__ 07. value = self.validate(value) 08. File '/base/python_lib/versions/1/google/appengine/ext/db/__init__.py', line 2322, in validate 09. (self.name, self.data_type.__name__)) 10. BadValueError: Property Duration must be a datetime 11.
CallStartTime, CallEndTime and Duration are all db.DateTimeProperty() types in GAE.
I had previously used django timesince to display the duration, but I need to do some additional calculations to figure out avg. duration of the events.
Any suggestions or pointers at what additional info might help are greatly appreciated!
Subtracting one
datetimefrom another will give you atimedelta. You can use that to create anotherdatetimeif you need to by adding it to or subtracting it from anotherdatetimeobject.How can you represent a duration with a single
datetimeobject, though?