By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

Trying to set a date field in a access databse

P: n/a
Hi,
I cannot get the following code to work

import win32com.client
import time

engine = win32com.client.Dispatch("DAO.DBEngine.36")
db=engine.OpenDatabase(r"testdate2.mdb")
access = db.OpenRecordset("select * from test")

access.AddNew()
access.Fields("test").value=time.strptime('10:00AM ', '%I:%M%p')
access.Update()

wherer test is a datetime field,
How can I do this???????
-Ted

Nov 5 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
te*******@gmail.com wrote:
Hi,
I cannot get the following code to work

import win32com.client
import time

engine = win32com.client.Dispatch("DAO.DBEngine.36")
db=engine.OpenDatabase(r"testdate2.mdb")
access = db.OpenRecordset("select * from test")

access.AddNew()
access.Fields("test").value=time.strptime('10:00AM ', '%I:%M%p')
access.Update()

wherer test is a datetime field,
How can I do this???????
A first step would be to find out what the expected type of the value
attribute is. For that you can put one record into the test table using
Access with the value 10:00AM for the test field and then run

# all code untested

import win32com.client

engine = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase("testdate2.mdb")
access = db.OpenRecordset("select * from test")

access.MoveFirst()
v = access.Fields("test").value
print type(v), v

If you cannot guess what Access expects from the output of the script, post
it here (in this thread, no need to start yet another one). Don't just
say "didn't work", give tracebacks and the exact code you ran.

Judging from
http://en.wikibooks.org/wiki/JET_Dat...ates_and_times
you will see something like

<type 'float'0.416666666667

If that's correct you can modify your script

def time_to_float(h, m, s):
return (h + m/60.0 + s/3600.0)/24.0

# ...

access.AddNew()
access.Fields("test").value = time_to_float(10, 0, 0)
access.Update()

Peter
Nov 5 '08 #2

P: n/a
You should be able to pass a PyTime or datetime.datetime object.

Roger

<te*******@gmail.comwrote in message
news:12**********************************@40g2000p rx.googlegroups.com...
Hi,
I cannot get the following code to work

import win32com.client
import time

engine = win32com.client.Dispatch("DAO.DBEngine.36")
db=engine.OpenDatabase(r"testdate2.mdb")
access = db.OpenRecordset("select * from test")

access.AddNew()
access.Fields("test").value=time.strptime('10:00AM ', '%I:%M%p')
access.Update()

wherer test is a datetime field,
How can I do this???????
-Ted

--
http://mail.python.org/mailman/listinfo/python-list


Nov 7 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.