473,508 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to set a date field in a access databse

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
2 2937
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2185
by: jason | last post by:
I'm tearing out my hair here: ACCESS 2000: When I attempt to overwrite a date in my date field with a new user selected valid date eg: 05/23/99 my date field changes to the TIME I updated the...
3
2053
by: Mike Dundee | last post by:
I am importing data into a new database (the database still has to be set up) and have a problem. The comma delimited text files I am importing have four fields containing date and date/times. ...
10
2955
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
3
2560
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
5
1342
by: diablo | last post by:
hi my access database may be placed on OS with different date settings - i.e. the date may be m/d/y or d/m/y how can i use this databse in a consisten way? I want to be able to sort on the...
2
2822
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID =...
7
4267
by: mewanalwis | last post by:
Dear Friends, I have a rather strange problem which invloves SQL server and ASP. The problem is this. I have an ASP application which use a SQL server. it saves date values with MM/dd/yyyy...
2
5142
by: hardik | last post by:
hi friends, i am really surprized the way access behaves in date fields i mean it's all ok when you have us time zone or us servers but if you have diffrent timezone like uk then access creates...
8
12815
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.