Take the 2-minute tour ×

I am using db.time property to save time required for a conversion:

my_model.conversion_time = time_taken = datetime.datetime.strptime(str(conversion_end - conversion_start), "%H:%M:%S.%f").time()

but when i see the data in datastore viewer , it is stored as datetime object with date of 1970-01-01. Does anybody know how I can just save the time in the datastore

share|improve this question
What is conversion_end and conversion_start? Are they datetime objects? –  Burhan Khalid Jul 15 '13 at 6:58
yes they are the datetime.now() objects –  omair_77 Jul 15 '13 at 7:02
add comment

1 Answer

I'm not sure why you have two inline assignments, but to get time out of a timedelta object:

>>> b
datetime.datetime(2013, 7, 15, 10, 21, 31, 599402)
>>> a
datetime.datetime(2013, 7, 15, 10, 18, 11, 251477)
>>> str(b-a)
>>> (datetime.datetime.min + (b-a)).time()
datetime.time(0, 3, 20, 347925)

In order to store only the time, you need to use TimeProperty in your datastore. It will be represented internally as datetime, but will store datetime.time() objects.

share|improve this answer
I have got time out of the datetime object successfully , but the problem is that GAE stores it as datetime object instead of just time. –  omair_77 Jul 15 '13 at 7:32
Show your code, many people use TimeProperty successfully. –  Tim Hoffman Jul 15 '13 at 10:51
add comment

Your Answer


