ODBC module and strange date reference <...>

Frank Millman frank at chagford.com
Thu Mar 2 13:34:18 CET 2006

dananrg at yahoo.com wrote:
> Been using the ODBC module for Python 2.1 (Win32) and had another
> question. When I return data from date columns, it's in a strange
> object form, e.g. <something or other> (don't have the output in front
> of me>.
> What's an easy way to convert date objects into a human-readable
> string? I'm using this module to extract data from an Oracle database,
> then converting it to a flat-file for import into an old flat-file
> database on a mainframe. I need to be able to change the date object
> into something the mainframe database will recognize.

odbc returns something called a DbiDate object.

You can convert this into a datetime object like this -

    import datetime
    dat = datetime.datetime.fromtimestamp(int(dbidate_object))

Now you can use any of the datetime attributes or methods to convert it
to human-readable form, such as dat.year, dat.month, str(dat), etc

I use odbc with MS Sql Server. I have never used Oracle, so I can't be
sure that it works the same way. Try it and see what happens.


Frank Millman

More information about the Python-list mailing list