I'm trying to insert date and time to SQL server in Linux (raspbian) environment using python language.So far i was able connect to MS Sql and also i created a table and im using pyodbc.
#! /user/bin/env python import pyodbc import datetime dsn = 'nicedcn' user = myid password = mypass database = myDB con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (dsn, user, password, database) cnxn = pyodbc.connect(con_string) cursor = cnxn.cursor() string = "CREATE TABLE Database3([row name] varchar(20), [my date] date), [my time] time)" cursor.execute(string) cnxn.commit() This part complied without any error.That means i have successfully created a table right? Or is there any issue?
I try to add date and time this way.
now = datetime.datetime.now() d1 = now.date() t2 = now.strftime("%H-%M-%S") cursor.execute("insert into Database3([row name], [my date], [my time]) values (?,?,?)", ('new1', d1, t2)) cnxn.commit() But i get this error. pyodbc.ProgrammingError:
('HY004', '[HY004] [FreeTDS] [SQL Server]Invalid data type (O) (SQLBindParameter)')
help me please. thanks in advance
"%H:%M:%S"?