SHARE
TWEET

Untitled

a guest Jul 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xlrd
  2. import mysql.connector
  3. import datetime
  4.  
  5. name= "Anand1989.xls"
  6. book=xlrd.open_workbook(name)
  7. worksheet = book.sheet_by_index(0)
  8. database = mysql.connector.connect (host="localhost", user = "root", passwd = "", db = "rainfall")
  9. cursor = database.cursor()
  10. query = """INSERT INTO  Anand1989(DATE) VALUES (%s)"""
  11. for r in range(1, worksheet.nrows):
  12.     DATE = worksheet.cell(r,0).value
  13.     date_time_obj = datetime.datetime.strptime(str(DATE), '%Y-%m-%d').date
  14.     values = (date_time_obj)
  15. cursor.execute(query, values)
  16. cursor.close()
  17. database.commit()
  18. database.close()
  19. print ("All Done! Bye, for now.")
  20.      
  21. Traceback (most recent call last):
  22. File "newins.py", line 46, in <module> date_time_obj = datetime.datetime.strptime(str(DATE), '%Y-%m-%d').date
  23. File "C:UsersstudentAppDataLocalProgramsPythonPython37-32lib_strptime.py", line 577, in _strptime_datetimet tt, fraction,gmtoff_fraction = _strptime(data_string, format)
  24. File "C:UsersstudentAppDataLocalProgramsPythonPython37-32lib_strptime.py", line 359, in _strptime (data_string, format)) ValueError: time data '32509.0' does not match format '%Y-%m-%d'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top