473,569 Members | 3,009 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.OpenD atabase(r"testd ate2.mdb")
access = db.OpenRecordse t("select * from test")

access.AddNew()
access.Fields(" test").value=ti me.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 2946
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.OpenD atabase(r"testd ate2.mdb")
access = db.OpenRecordse t("select * from test")

access.AddNew()
access.Fields(" test").value=ti me.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.OpenData base("testdate2 .mdb")
access = db.OpenRecordse t("select * from test")

access.MoveFirs t()
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.416666 666667

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(1 0, 0, 0)
access.Update()

Peter
Nov 5 '08 #2
You should be able to pass a PyTime or datetime.dateti me object.

Roger

<te*******@gmai l.comwrote in message
news:12******** *************** ***********@40g 2000prx.googleg roups.com...
Hi,
I cannot get the following code to work

import win32com.client
import time

engine = win32com.client .Dispatch("DAO. DBEngine.36")
db=engine.OpenD atabase(r"testd ate2.mdb")
access = db.OpenRecordse t("select * from test")

access.AddNew()
access.Fields(" test").value=ti me.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
2192
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 field and does not display my desired date: 05/23/99 Instead it reads: 12:12:03 AM I am going nuts - even considering converting the field to...
3
2057
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. One field in particular has a date format of MMM dd yyyy hh:mmAM eg Feb 20 2004 10:00AM. The other fields import correctly (although I haven't run a...
10
2962
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 1jan2003. How do I remove the dates , 2jan2003 til 31jan2003 without removing them from the table, from the Query? (Because I want to use the data for...
3
2561
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, IT.itemid, IT.date,
5
1349
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 date for example 'select * from ... mydatetime asc'
2
2828
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 = 345" Note : The above string is stored and the dates are in US format. so
7
4271
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 format. the SQL server and every other computer is configured to MM/dd/yyyy format in reginol settings. The DSN which use to connect to SQL server...
2
5152
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 so many problems .... first of all i try access with uk settings in date/time in field but access changes date after 09/11 to 11/09 i don't know...
8
12818
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 the dates the employee took off from work. (I have the calander add-in 8.0 setup to easily select the dates already) There are two Date Fields,...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.