I am trying to insert the current datetime into a datetime2
type column of a SQL Server table:
creationdatetime = datetime.datetime.now() # 2021-11-20 21:35:40.851495
sql = ("INSERT INTO [SCHEMA].[TABLE] (\n"
"[CreationDateTime]) \n"
f"VALUES ('{creationdatetime}')")
cursor.execute(sql)
cursor.commit()
I keep on getting this error:
[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '2021'. (102) (SQLExecDirectW)
Already spent like 3 hours to fix this issue....
Any help is really appreciated
Thank you