Python ADO Date Time database fields

goldtech goldtech at worldpost.com
Thu Jan 24 18:55:38 EST 2008


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



More information about the Python-list mailing list