Help with DateTimeProperty datastore stuff

351 views
Skip to first unread message

Sam G

unread,
Sep 21, 2008, 1:13:47 AM9/21/08
to Google App Engine
Hello (again),

I'm a bit mystified about the db.DateTimeProperty. In the Datastore
API's Types and Properties documentation, it lists the Python object
type as datetime.datetime.

However, when I try to convert this datetime.datetime object to a
string, I get a "argument must be 9-item sequence, not
datetime.datetime" error.

Here's the code:

import time
...
message.timestamp = time.strftime("%I:%M %p", message.created)


The variable "message.created" is a DateTimeProperty that is retrieved
from the datastore.

Is there an easier way (or one that works) for converting a
DateTimeProperty to something like "11:34 AM"?

Alexander Kojevnikov

unread,
Sep 21, 2008, 2:02:05 AM9/21/08
to Google App Engine
Try this:

message.timestamp = message.created.strftime("%I:%M %p")

You are confusing time.strftime() with datetime.datetime.strftime()

Sam G

unread,
Sep 21, 2008, 3:10:36 PM9/21/08
to Google App Engine
Worked like a charm.

Thanks again, Alexander.

On Sep 20, 11:02 pm, Alexander Kojevnikov <alexan...@kojevnikov.com>
wrote:
Reply all
Reply to author
Forward
0 new messages