Python ADO Date Time database fields

Mike Driscoll kyosohma at gmail.com
Thu Jan 24 20:03:38 EST 2008


On Jan 24, 5:55 pm, goldtech <goldt... at worldpost.com> wrote:
> Hi,
>
> Given an MS-Access table with a date type field with a value of:
> 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field.
>
> I want to print exactly what's in the field, ie. "12:00:00 AM". What I
> get printed is:   12/30/0/ 00:00:00
>
> I try:
>
> import win32com.client
> from win32.client import Dispatch
>
> oConn=Dispatch('ADODB.Connection')
> db = r'C:\mydb.mdb'
> oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; data Source="+db)
> oRS = Dispatch('ADODB.RecordSet')
> oRS.ActiveConnection =  oConn
> c = oConn.OpenSchema(20)
>
> while not c.EOF:
>     tn = c.Fields.Item('Table_Name').Value
>     oRS.Open(tn)
>     (oRS, dt) = oConn.Execute('SELECT date_field FROM '+tn+' GROUP BY
> date_field')
>     while not oRS.EOF:
>         print oRS.Fields(dt).Value  # print here
>          oRS.MoveNext()
>     c.MoveNext()
>
> oRS.Close()
> oConn.Close()
> # end
>
> What I get printed is:   12/30/0/ 00:00:00
>
> What do I to get exactly what's in the field?
>
> Thanks,
>
> Lee G

I don't know for sure, so I practiced my Google-Fu and found this
recipe which might be of use to you:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52267

I also found this script, which might help you interface better with
Access:

http://www.ecp.cc/pyado.html

And then there just connecting to it with the adodb module:

http://phplens.com/lens/adodb/adodb-py-docs.htm

Mike



More information about the Python-list mailing list