Rishav Sharan
Rishav Sharan

Reputation: 2932

pulling data from date field in google app engine form

I have created a simple form in GAE-python which contains a date field. i tried pulling in the data from it but keep on getting an exception.
my code is;

temp_var = datetime.strptime(cgi.escape(self.request.get('exam_date')),"%m/%d/%Y")
pledge_data.checkup_date = temp_var.strftime('%m/%d/%Y')

the exception is;

BadValueError: Property checkup_date must be a date

i am confused here. shouldn't strftime convert it to a date object?

EDIT: the date i am parsing is a string "05/23/2011"

Upvotes: 0

Views: 355

Answers (2)

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15310

With the first line you already get a date:

temp_var = datetime.strptime("05/23/2011","%m/%d/%Y")

temp_var
>> datetime.datetime(2011, 5, 23, 0, 0)

Docs here.

Upvotes: 1

aschmid00
aschmid00

Reputation: 7158

you are doing a strptime on the exam_date which returns you a date and right after you are reconverting it to a string with strftime

try:

temp_var = datetime.strptime(cgi.escape(self.request.get('exam_date')),"%m/%d/%Y")
pledge_data.checkup_date = temp_var

Upvotes: 4

Related Questions