pyodbc handles well datetime.datetime objects with DATETIME column. No special formatting needed.
But it fails with datetime.date objects and DATE column:[HY004] [FreeTDS][SQL Server]Invalid data type (0) (SQLBindParameter)
One way is to insert datetime.date object as string, with .isoformat() method.
But:
d1 = dt.date.today() d2 = dt.datetime.now() print(isinstance(d1, dt.date)) print(isinstance(d1, dt.datetime)) print(isinstance(d2, dt.date)) print(isinstance(d2, dt.datetime)) returns
True False True True isn't there a better way than testing like that?
if isinstance(d1, dt.date) and not isinstance(d1, dt.datetime): d1 = d1.isoformat()
FreeTDSto connect? What's your FreeTDS and unixODBC configuration? Or are you connecting from Windows? This may be caused by using too low a TDS Version.datetime.dateparameter values when using Microsoft's "ODBC Driver 13 for SQL Server".