Updating Date & Time into MySQL via python -
i trying update date & time columns in mysqldb database. have 2 columns name date1 , time1 , both type text. python code
import mysqldb import datetime db = mysqldb.connect('localhost','admin','admin','dbname') cur = db.cursor() = datetime.datetime.strftime(datetime.date.today(),'%y-%m-%d')) cur.execute('update data set date1={0}'.format(a)) db.commit()
but after code executes see value in column set '2000'.
i tried several datetypes in mysql - varchar2, date, datetime show '2000' or '0000-00-00'.
when run sql query directly works fine:
update `data` set `date1`='22-04-1994'
i googled error , tried this:
a = datetime.date.today() = a.isoformat()
but shows in database 2000.
edit: tried using {0} instead of +a. still coming 2000.
i using mysql version 5.5.51-38.2
think query does, since concatenate strings. can print out. since don't put date quotes considered calculation. you're saying:
date1=2016-11-5
this of course 2000, want
date1='2016-11-5'
the best way use parameters underlying system doing rather concatenating strings , trying escape them correctly.
Comments
Post a Comment