st4ck0v3rfl0w
st4ck0v3rfl0w

Reputation: 6755

String to Time Python strptime

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'

Upvotes: 0

Views: 93

Answers (1)

Ankit Jaiswal
Ankit Jaiswal

Reputation: 23437

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.

Upvotes: 3

Related Questions