[python-win32] Python help for Access database
Robert Brewer
fumanchu at amor.org
Mon Jul 31 21:08:18 CEST 2006
Shakir wrote:
> I need help for inserting recods into the access database using python
> script through ODBC. I can insert data without any problem if I hard
> coded the run_Date field. But I need run_Date field should be
> mytime. I really appreciate if anyone can help me.
>
> The script is as follows:
> ...
> mytime = time.strftime('%m/%d/%Y')
> mytimeYMD = time.strftime('%Y%m%d')
> conn = odbc.odbc("test1_Data")
> cursor = conn.cursor()
>
> # data type in mdb is as follows: application -> Text, Run_Date ->
> # Date, Run_dateYMD -> number, status -> Script
>
> cursor.execute("INSERT INTO local_cmgenadm
> (Application,Run_Date,Run_DateYMD,status) values
> (\'rimDev2PrdMdbDistrictPermit\',\'%s\', \'20060731\' ,
> \'Good\')")%mytime
MS Access Dates are best input using the #date# syntax. Here's an
example to convert a datetime.datetime object to that format:
return ('#%s/%s/%s %02d:%02d:%02d#' %
(value.month, value.day, value.year,
value.hour, value.minute, value.second))
Should be easy enough to adapt to time.time.
Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
More information about the Python-win32
mailing list