Now you are passing the time.struct_time object, MySQL knows nothing about something. You need to format the timestamp in a format that MySQL understands. Unfortunately, the MySQLdb library MySQLdb not do this for you.
This will be easiest with the datetime module, but you can also do this with the time module:
import datetime a = datetime.datetime.strptime('my date', "%b %d %Y %H:%M") cursor.execute('INSERT INTO myTable (Date) VALUES(%s)', (a.strftime('%Y-%m-%d %H:%M:%S'),))
Calling the .strftime() method of the datetime.datetime object formats the information in such a way that MySQL will accept.
Performing one task using only the time module:
import time a = time.strptime('my date', "%b %d %Y %H:%M") cursor.execute('INSERT INTO myTable (Date) VALUES(%s)', (time.strftime('%Y-%m-%d %H:%M:%S', a),))
source share