Bogdan
Bogdan

Reputation: 243

Datetime don't match my format

I have a date string with this format '01/30/15' so its 'mm/dd/yy' format I think I parse a csv file, but when I try:

import datetime
for row in reader:
  dt = datetime.datetime.strptime(row['Date'],"mm/dd/yy")
  print dt

Will return :

ValueError: time data '01/30/15' does not match format 'mm/dd/yy'

Upvotes: 2

Views: 71

Answers (2)

Andy
Andy

Reputation: 50560

You are using the improper format string. You want: %m/%d/%y

Example:

>>> import datetime
>>> s = "01/30/15"
>>> dt = datetime.datetime.strptime(s, "%m/%d/%y")
>>> dt
datetime.datetime(2015, 1, 30, 0, 0)

Upvotes: 3

Chr
Chr

Reputation: 965

dt = datetime.datetime.strptime(row['Date'], "%m/%d/%y")

Upvotes: 1

Related Questions