Updating Date & Time Into Mysql Via Python
I am trying to update my date & time columns in my MySQLdb database. I have 2 columns by the name date1 and time1 and both are type TEXT. This is my python code import MySQLdb
Solution 1:
Think what your query does, since you concatenate strings. You can even print it out. Since you don't put the date into quotes it will be considered a calculation. So you're saying:
date1=2016-11-5
This is of course 2000, but you want
date1='2016-11-5'
The best way is to use parameters so the underlying system is doing all this for you rather than you concatenating strings and trying to escape them correctly.
Solution 2:
You should be using parameters. But, if not, you need to include single quotes around date constants:
cur.update('update Data set date1 = '{0}'".format(a))
Post a Comment for "Updating Date & Time Into Mysql Via Python"