0

I'm pulling the date value from gmail and trying to perform some functions on it. First I simply want to display it, but I can't even do that. See my code and error below.

from datetime import datetime
timeString = 'Sat, 2 Aug 2014 09:29:31 -0700'
myTime = datetime.strptime(timeString, '%m-%d-%Y %I:%M %p')

Here's the error I get. Do you think its the -0700 that's getting in the way?

ValueError: time data 'Sat, 2 Aug 2014 09:29:31 -0700' does not match format '%m-%d-%Y %I:%M %p'
davejagoda
  • 2,420
  • 1
  • 20
  • 27
st4ck0v3rfl0w
  • 6,665
  • 15
  • 45
  • 48

1 Answers1

3

As the error message suggests, you need to put the same format as your date string is in, I've not tried it, but something like this should work:

myTime = datetime.strptime(timeString, '%a, %d %b %Y %I:%M:%S %z')

Check here for complete details.

Ankit Jaiswal
  • 22,859
  • 5
  • 41
  • 64
  • `%z` is not supported by `datetime.strptime` as of python 2.6 according to [this question](http://stackoverflow.com/questions/1101508/how-to-parse-dates-with-0400-timezone-string-in-python) however your code runs on my Python 3.4.1, so I guess this is highly version-specific. – Adam Smith Aug 07 '14 at 04:23
  • 1
    @AdamSmith You are right, %z was removed in python 2.6, however this has again been added to python 3.2+ versions. – Ankit Jaiswal Aug 07 '14 at 04:35