Daniel Wogan
Daniel Wogan

Reputation: 21

ValueError: time data '12/16/2016' does not match format '%d/%m/%Y'

I've Imported CSV, and I'm trying to Print out Products in a CSV File that were Sold on a Weekend, but I can't Convert the Calendar Dates to Weekdays for some reason?

Look = open("ShopRecords.csv", "r")
#Store The Content Of The File In A ReadCSV.
ReadFile = list(csv.reader(Look))
ReadFile.pop(0)
print(ReadFile)
#Loop Through Each Line In The Record.
for Record in ReadFile:
    DateConvert = datetime.datetime.strptime(Record[2], "%d/%m/%Y")
    print(DateConvert)
#If The Line Contains Saturday, Print The Item Name, Which Is The Second Item.
    if Sat in Record:
        print(Record[1])
#If The Line Contains Sunday, Print The Item Name, Just Like If It's Saturday.
    if Sun in Record:
        print(Record[1])

Upvotes: 2

Views: 35

Answers (1)

heemayl
heemayl

Reputation: 42147

%m is the month specifier, and 16 can't be a month number, so it must be 12, and 16 should be the date number (%d). So, you need the format:

%m/%d/%Y

to match 12/16/2016.

Upvotes: 3

Related Questions