0

Trying to parse a date to a string and getting this error. Not able to figure out which variable is incorrect.

ValueError: time data '12:00 AM IST on June 01, 2017' does not match format '%I:%M %p %Z on %B %d, %Y'

Here is the code

data = sorted(data['data'], key=lambda x: datetime.datetime.strptime(x['date']['pretty'], '%I:%M %p %Z on %B %d, %Y'), reverse=False)
  • Have you tried using `strftime` to see if you can recreate your date data with your format code? – Bill Apr 19 '18 at 15:56
  • See [this answer](https://stackoverflow.com/a/23704862/1609514) regarding the `%Z` timezone directive. – Bill Apr 19 '18 at 16:03
  • Replacing IST with UTC works - so this is definitely something to do with time zones. – jpp Apr 19 '18 at 16:08
  • What is `IST` supposed to refer to? Irish Standard Time, India Standard Time, Israel Standard Time, etc? A proper time stamp would use an offset from UTC, not a text label, to designate a timezone. – chepner Apr 19 '18 at 17:16
  • @chepner Indian Standard Time. I receive this time data from an external api call which returns a time data in this format. Ill strip the 'IST' part of it as i dont need it further in my program. – Clyde Shelton Apr 20 '18 at 15:49

1 Answers1

0

dateutil might help you

Demo:

from dateutil import parser
s = '12:00 AM IST on June 01, 2017'
print(parser.parse(s))

Output:

2017-06-01 00:00:00

Note: The issue you are having is with converting the zone IST

Rakesh
  • 81,458
  • 17
  • 76
  • 113