2

I have the date of 1515 in my data set column 4, is there any way to bypass this error?

cols[4] = cols[4] and cols[4].strftime("%d/%m/%Y") or ""
ValueError: year=1515 is before 1900; the datetime strftime() methods require year >= 1900

Here is the exact code:

cursor.execute(SQL)
filename = r"C:\Projects\OPEN_KCI3.csv"

with open(filename, "wb") as fout:
writer = csv.writer(fout)
#writer.writerow([i[0] for i in cursor.description ]) # heading row

for row in cursor.fetchall():
    cols = list(row)
    cols[3] = cols[3] and cols[3].strftime("%d/%m/%Y") or ""
    cols[4] = cols[4] and cols[4].strftime("%d/%m/%Y") or ""
    writer.writerow(cols)

cursor.close()
connection.close()
Lee Murray
  • 315
  • 1
  • 6
  • 19
  • 2
    Possible duplicate of [Use datetime.strftime() on years before 1900? ("require year >= 1900")](http://stackoverflow.com/questions/10263956/use-datetime-strftime-on-years-before-1900-require-year-1900) – fredtantini Nov 21 '16 at 11:52

0 Answers0