I have a date column in a MySQL table. I want to insert a datetime.datetime() object into this column. What should I be using in the execute statement?
datetime.datetime()
Try using now.date() to get a Date object rather than a DateTime.
now.date()
Date
DateTime
If that doesn't work, then converting that to a string should work:
now = datetime.datetime(2009,5,5) str_now = now.date().isoformat() cursor.execute('INSERT INTO table (name, id, datecolumn) VALUES (%s,%s,%s)', ('name',4,str_now))