I have found answers to question like this one helpful but not complete for my problem.
I have a form where the user automatically produces a date. I would like to store that as a date time.
I don’t need any of the information after the seconds, but I cannot find a datetime.datetime.strptime code to translate the remaining stuff. So I would either like a strptime code that works for python2.7 on google app engine, or a string editing trick for removing the extra information that is not needed.
date-from-user=’2012-09-22 07:36:36.333373-05:00′
You can slice your string to only select the first 19 characters:
This let’s you parse the date without having to bother with the microseconds and timezone.
Do note that you probably do want to parse the timezone too though. You can use the
iso8601module to handle the whole format, without the need to slice:The
iso8601module is written in pure python and works without problems on the Google App Engine.