Sto tentando di inserire un valore datetime in una tabella MS SQL Server utilizzando pyodbc. Se lo faccio manualmente, qualcosa come:Inserimento di datetime in una tabella MS SQL utilizzando pyodbc
cursor.execute("""insert into currentvalue(value1,currentdatetime)
values(55,'2014-06-27 16:42:48.533')""")
non ho alcun problema a tutti, ma quando cerco di fare:
currenttime = str(datetime.datetime.now())
cursor.execute("""insert into currentvalue(value1,currentdatetime)
values(55,"""+ currenttime+")")
ho ottenuto questo errore:
SQL server Incorrect syntax near '07' which i think is the number after the date and starting the time.
Inoltre ho provato questo:
currenttime = "'"+str(datetime.datetime.now())+"'"
e ora questo errore viene in su:
Conversion failed when converting date and/or time from character string.
Usa [parametri] (https://code.google.com/p/pyodbc/wiki/GettingStarted#Parameters). – Bryan