473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Python ADO Date Time database fields

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
Jan 25 '08 #1
4 2426
On Jan 24, 5:55 pm, goldtech <goldt...@worldpost.comwrote:
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
I don't know for sure, so I practiced my Google-Fu and found this
recipe which might be of use to you:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/52267

I also found this script, which might help you interface better with
Access:

http://www.ecp.cc/pyado.html

And then there just connecting to it with the adodb module:

http://phplens.com/lens/adodb/adodb-py-docs.htm

Mike
Jan 25 '08 #2
On Jan 25, 10:55 am, goldtech <goldt...@worldpost.comwrote:
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:
[snip]
print oRS.Fields(dt).Value # print here
try this:

val = oRS.Fields(dt).Value
print type(val)
print float(val)

If the last one gives you 0.0, then you have got exactly what's in the
database -- stored as a fraction of a day. Six AM would give you 0.25.

Converting that to 24 hour clock is easy:
>>val = 0.12345
seconds = int(round(val * 60 * 60 * 24))
minutes, second = divmod(seconds, 60)
hour, minute = divmod(minutes, 60)
'%02d:%02d:%02d' % (hour, minute, second)
'02:57:46'
>>((((46/60.)+57)/60.)+2)/24. # checking
0.12344907407407407

If you don't get 0.0, let us know what you did get.

HTH,
John
Jan 25 '08 #3
snip
>
try this:

val = oRS.Fields(dt).Value
print type(val)
this gives: <type 'time'>
print float(val)
yes, it gives 0.0

But there should be a way to print what is *actually in the field*.
When I open the DB table in Access I see: 12:00:00 AM.

That's what I want - the value, and the form of the value, exactly as
seen in the field...

As an aside, the roughly eqivalent code in Perl will print the
"12:00:00 AM" - (the trick for the date types in Perl is to add: "use
Win32::OLE::Variant;"

There has to be a way:^)

snip
Jan 25 '08 #4
On Jan 25, 7:48 am, goldtech <goldt...@worldpost.comwrote:
snip
try this:
val = oRS.Fields(dt).Value
print type(val)

this gives: <type 'time'>
print float(val)

yes, it gives 0.0

But there should be a way to print what is *actually in the field*.
When I open the DB table in Access I see: 12:00:00 AM.

That's what I want - the value, and the form of the value, exactly as
seen in the field...

As an aside, the roughly eqivalent code in Perl will print the
"12:00:00 AM" - (the trick for the date types in Perl is to add: "use
Win32::OLE::Variant;"

There has to be a way:^)

snip
You could try posting to the PyWin32 group too. They would probably
know.

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

Mike
Jan 25 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: webmaster | last post by:
Hi, I'm desperatly trying to use Kinfxdb, but I have numerous segmentation faults, who lead my Zope to crash. It mostly occurs when I try to work with "date" fields (with an Informix Online...
1
by: David Mertz, Ph.D. | last post by:
I decided to write a pure Python hashcash implementation. I have seen David McNab's Python implementation. Unfortunately, as near as I can tell (which is supported on the hashcash mailing list...
32
by: Philippe C. Martin | last post by:
Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
3
by: Ralf | last post by:
Is their anybody with xperience in using the both and can provide me with some xamples. Thx a lot Ralf
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
3
by: Ethan Furman | last post by:
len wrote: I've never had the (mis?)fortune to work with COBOL -- what are the files like? Fixed format, or something like a dBase III style? I
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.