According to the documentation (https://code.google.com/p/pyodbc/wiki/DataTypes) the SQL Server DATE type is mapped to datetime.date, however I seem to be getting back strings instead.
Consider the following table definition in SQL Server 2008 (SP1) [10.0.2531.0 (X64)]:
CREATE TABLE dbo.Contract(
id INT NOT NULL,
name VARCHAR(23) NOT NULL,
some_date DATE NULL,
write_time DATETIME NOT NULL)
Accessed with the following code:
import pyodbc
from pprint import pformat
db = pyodbc.connect("DRIVER={SQL Server};SERVER=.\\SQLEXPRESS;DATABASE=scratch;Trusted_Connection=yes")
print pformat(db.cursor().execute("select * from Contract").description)
The cursor description is:
(('id', <type 'int'>, None, 10, 10, 0, False),
('name', <type 'str'>, None, 23, 23, 0, False),
('some_date', <type 'unicode'>, None, 10, 10, 0, True),
('write_time', <type 'datetime.datetime'>, None, 23, 23, 3, False))
Note that the some_date column is indicated as type unicode string, however, in the database this column is defined as DATE.
(On the other hand, the write_time column is correctly mapped to datetime.datetime.)
pyodbc 2.1.8 tested on Windows 7 and RedHat Linux.
This is caused by the driver. On Windows, you need to use DRIVER={SQL Server Native Client 10.0} for a driver that understands the ODBC date type. I don't know what would be required for FreeTDS.