473,787 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odbc DbiDate date conversion

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
<DbiDate object at 0x0087E040>
>>str(birthd)
'e\x00\x00d\x00 \x00\x19d\x01\x 00\x19Z\x01\x00 d\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
Sep 26 '06 #1
7 4063

flupke wrote:
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.dateti me.fromtimestam p(int(dbidate))

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

HTH

Frank Millman

Sep 26 '06 #2
Frank Millman schreef:
flupke wrote:
>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.dateti me.fromtimestam p(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:
>>mydate = datetime.dateti me.fromtimestam p(int(birthd))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: timestamp out of range for platform localtime()/gmtime()
function

Regards,
Benedict
Sep 26 '06 #3

flupke wrote:
Frank Millman schreef:
flupke wrote:
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.dateti me.fromtimestam p(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:
>mydate = datetime.dateti me.fromtimestam p(int(birthd))
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

Sep 26 '06 #4
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"."n ummer" 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
Sep 26 '06 #5
Frank Millman schreef:
<snip>
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
Sep 26 '06 #6

flupke wrote:
Frank Millman schreef:
<snip>
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?
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/pyd...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.dateti me 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.source forge.net. I will give it a try.

Frank

Sep 27 '06 #7
Frank Millman schreef:
<snip>
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/pyd...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.dateti me 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.source forge.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
Sep 27 '06 #8

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

Similar topics

10
2875
by: Kim Petersen | last post by:
Regarding ODBC usage in Python... it seems to me that there is a couple of ways to use odbc from python, one of these is the MX version - now that one has a pretty steep licence cost (imho). So now comes my question (from reading this group quite a bit): - what is the basic reason for using MX versus the others? - why do you (newsgroup) seem to think that this package is the preferred one? - in case above is incorrect - what package...
1
3293
by: Fons Dijkstra | last post by:
Hello, I'm using the mx.ODBC.Windows package in order to read/write a MSAccess database. Everything works fine apart from the DATE format handling. I'm using the default "datetimeformat" (i.e. DATETIME_DATETIMEFORMAT) as suggested. The date columns in the MSAccess database have "Short Date" format. When I read a DATE item everything works fine, like:
0
1581
by: Wedrowiec | last post by:
I have a problem for experienced programmers. The following code should copy data between two different databases: import dbi,odbc conn1=odbc.odbc('mysql'); conn2=odbc.odbc('sqlite') c1 = conn1.cursor(); c2 = conn2.cursor() c1.execute("SELECT field1, field2 FROM table1") rows = c1.fetchall() c2.executemany('INSERT INTO table1 (field1=%s,field2=%s)', rows)
1
3275
by: Frank Millman | last post by:
Hi all I am using odbc from win32 extensions to connect to MS SQL Server. I use mx.DateTime to handle dates. When I select a datetime column from the database, odbc returns something called a DbiDate object. I cannot find out any information on this type, but mx can convert it to a mx.DateTime object using DateTimeFrom(), which is really all that I need. I am looking into changing from mx.DateTime to using the builtin
0
1378
by: MBR | last post by:
Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 19 Organization: Arcor NNTP-Posting-Date: 02 Dec 2004 12:46:22 MET NNTP-Posting-Host: a58bf304.newsread4.arcor-online.net X-Trace: DXC=Gl27MQXTJCTD__2dTlB=EkaMXXY;eg@jLYe\NQ\`f2NU8P_mnR6@1cH6TQE]KL?G7HZePceTdIGCVST] X-Complaints-To: abuse@arcor.de Xref: number1.nntp.dca.giganews.com mailing.database.mysql-win32:6848 mailing.database.mysql:143134
0
2217
by: john_20_28_2000 | last post by:
Hi, I am trying to add a new ODBC entry for Sql Server, XP Pro. SP2, sqlserver odbc 2.000.8xxxxxxx. All it does when I hit "Add" show the hour glass for a millisecond and then it does nothing. I also had a program that created entries in the background for its use. The program kept failing, so I checked the ODBC entries. This is where I found I could not add. I also could not configure existing ones. (the program has nothing to do...
0
2384
by: Julia Baresch | last post by:
Everyone, I posted the message below back in February and didn't get any information. I also wasn't able to find any documentation in MS Help, web site, or other groups. I'm posting now with results of my research in case anyone else might need this information. I consulted with my MIS colleague, and he said it would be ok to have each merge file pull the whole database when the criteria screen is opened. His reasoning was that it...
8
1898
by: acb | last post by:
Hello, I am a beginner in ASP.NET and C# having programmed in VB (not the .NET flavour) in the past. I am looking for assistance in converting a functional VB.NET aspx page to C#. I am trying to extract data from a database using ODBC. A search on the internet led me to the page at http://forums.asp.net/27667/ShowPost.aspx that contained a functional example in VB.NET. This worked on my computer. Hereunder is a snippet
14
1788
by: dananrg | last post by:
Been using the ODBC module for Python 2.1 (Win32) and had another question. When I return data from date columns, it's in a strange object form, e.g. <something or other> (don't have the output in front of me>. What's an easy way to convert date objects into a human-readable string? I'm using this module to extract data from an Oracle database, then converting it to a flat-file for import into an old flat-file database on a mainframe. I...
0
10363
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
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.