odbc DbiDate date conversion

F

flupke

I'm using a solid DB and i'm accessing it via the odbc module
(activepython).
I get a DbiDate object returned but i don't find a way to decently print
it or get a format like %d/%m%/%y.

I found a few posts but the code doesn't work.
birthd = results[0][4] #info from db
birthd
str(birthd) 'e\x00\x00d\x00\x00\x19d\x01\x00\x19Z\x01\x00d\x02\x00S\x00[4]\n\x00'
t = time.strftime('%d %B %Y', birthd)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument must be 9-item sequence, not DbiDate

How can i convert this DbiDate to a string formated like '%d %B %Y'

I look at the DB API 2.0 but couldn't find the relevant info.

Thanks,
Benedict
 
F

Frank Millman

flupke said:
I'm using a solid DB and i'm accessing it via the odbc module
(activepython).
I get a DbiDate object returned but i don't find a way to decently print
it or get a format like %d/%m%/%y.

I convert it to a datetime() instance, like this -

mydate = datetime.datetime.fromtimestamp(int(dbidate))

Then I can use all the functionality of the datetime module.

HTH

Frank Millman
 
F

flupke

Frank Millman schreef:
I convert it to a datetime() instance, like this -

mydate = datetime.datetime.fromtimestamp(int(dbidate))

Then I can use all the functionality of the datetime module.

HTH

Frank Millman

Hi Frank,

i tried it and i end up with this:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: timestamp out of range for platform localtime()/gmtime()
function

Regards,
Benedict
 
F

Frank Millman

flupke said:
Frank Millman schreef:

Hi Frank,

i tried it and i end up with this:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: timestamp out of range for platform localtime()/gmtime()
function

Well waddyaknow - I get exactly the same, for dates earlier than
1970-01-02. Thanks for finding a bug that would have bitten me sooner
or later.

I will do some investigation. If I find an answer I will post it here,
unless some kind soul saves me the trouble and beats me to it.

Frank
 
F

flupke

flupke schreef:
<snip>
When i do the same sql from a client, i get this: 1961-02-15
Seems ok.
If i check the catalog, the native field type is listed as 10 positions
and of type date.

Yet when i print it after i got the values i get this which looks very
weird (print "value ",str(i)," type ",type(i)):

value "main_kamer"."nummer" m" type <type 'DbiDate'>

The type is ok but the result of str(i) looks wrong.
Or is it due to conversion by str?

Regards,
Benedict
 
F

flupke

Frank Millman schreef:
Well waddyaknow - I get exactly the same, for dates earlier than
1970-01-02. Thanks for finding a bug that would have bitten me sooner
or later.

I will do some investigation. If I find an answer I will post it here,
unless some kind soul saves me the trouble and beats me to it.

Frank

Thanks for investigating it so far Frank.

Is there a workaround to parse that date and get the date info that i want?

Regards,
Benedict
 
F

Frank Millman

flupke said:
Frank Millman schreef:


Thanks for investigating it so far Frank.

Is there a workaround to parse that date and get the date info that i want?

Not that I know of. The results of my investigations so far seem to
indicate that we have a problem :-(

Here is a link to an article dated 1998 -
https://svn.python.org/www/trunk/pydotorg/windows/OdbcHints.html

Among other interesting stuff, it states -

"Notice that result values are converted to Python objects. Dates in
particular are returned as dbiDate objects. This can be a serious
limitation, because dbiDate can not represent dates prior to the UNIX
epoch (1 Jan 1970 00:00:00 GMT). If you try to retrieve earlier dates,
you'll get garbage and may even provoke a crash."

I contacted Mark Hammond, author of the win32 extensions, to ask if
there was a solution and particularly to suggest a modification to
return a datetime.datetime object. This was his reply -

"I'd be happy with an option to use the datetime module - maybe it
could even be on the cursor? However, I wont have time to do this in
the short term.
You could consider using ADO via win32com too..."

It looks as if we will have to use ADO for now. There is an 'adodbapi'
module available which is DB-API 2.0 compliant -
adodbapi.sourceforge.net. I will give it a try.

Frank
 
F

flupke

Frank Millman schreef:
Not that I know of. The results of my investigations so far seem to
indicate that we have a problem :-(

Here is a link to an article dated 1998 -
https://svn.python.org/www/trunk/pydotorg/windows/OdbcHints.html

Among other interesting stuff, it states -

"Notice that result values are converted to Python objects. Dates in
particular are returned as dbiDate objects. This can be a serious
limitation, because dbiDate can not represent dates prior to the UNIX
epoch (1 Jan 1970 00:00:00 GMT). If you try to retrieve earlier dates,
you'll get garbage and may even provoke a crash."

I contacted Mark Hammond, author of the win32 extensions, to ask if
there was a solution and particularly to suggest a modification to
return a datetime.datetime object. This was his reply -

"I'd be happy with an option to use the datetime module - maybe it
could even be on the cursor? However, I wont have time to do this in
the short term.
You could consider using ADO via win32com too..."

It looks as if we will have to use ADO for now. There is an 'adodbapi'
module available which is DB-API 2.0 compliant -
adodbapi.sourceforge.net. I will give it a try.

Frank

Frank,

thanks for your effort. Looks indeed like it's not going to be solved in
the short term. I will give adodbapi a whirl then.

Thanks,
Benedict
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top