[Tutor] datetimetype vs datetime.datetime

Kent Johnson kent37 at tds.net
Sat Nov 11 13:53:36 CET 2006


johnf wrote:
> Hi
> I'm working on a python interface to freetds.  And freetds can access MS SQL 
> database engines.  But I'm having trouble with datatime datatypes.  
> 
> The python module I'm using is MSSQL.py written back in 2003.  After getting 

Why are you using such an old version?

> it compiled access to MS SQL works if I stay with simple datatypes (int, 
> varchar).  But when the table has a datetime field the MSSQL.py module 
> returns a 'DateTimeType' i.e.
> Jan 13 2006 12:00AM
> 
> The question is how can I convert the 'DateTimeType' to a datetime.datetime?

Presumably DateTimeType is the type of mx.DateTime? If so, this is a 
rich data type that you might be able to use directly. It was popular 
before Python's datetime module was released. See
http://www.egenix.com/files/python/mxDateTime.html#DateTime

If you have to convert to datetime.datetime just use the DateTime 
attributes to extract the data:
datetime.datetime(mxd.year, mxd.month, mxd.day)

Kent

> 
> John
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 




More information about the Tutor mailing list