mercredi 9 mars 2016

python Datetime and SQLite

I'd like to enter the current time into my sql table using sqlite3 and python. This code results in an error.

cur.execute('''
CREATE TABLE IF NOT EXISTS Finance (date DATE, time TEXT, cost FLOAT, item TEXT, cat TEXT)''')

time = datetime.datetime.now().time()

cur.execute('''INSERT INTO Finance (date, time, cost, item, cat) VALUES ( ?, ?, ?, ?, ? )''', ( date, time, cost, item, cat ) )

This is the error:

ur.execute('''INSERT INTO Finance (date, time, cost, item, cat) VALUES ( ?, ?, ?, ?, ? )''', ( date, time, cost, item, cat ) )
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.

However if I use this format for time,

time = datetime.datetime.now.ctime()

I can input the data with "Wed Mar 9 15:18:37 2016" format.

I just want the time, not the date and time. What datatype should I use? Thanks

Aucun commentaire:

Enregistrer un commentaire