By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

mx.DateTime.Error: cannot convert value to a time value

P: n/a
Ladies and gentlemen,

I've imported some data from a MySQL database into a Python dictionary. I'm
attempting to tidy up the date fields, but I'm receiving a
'mx.DateTime.Error: cannot convert value to a time value' error. It's
related to glibc returning an error to a pre-1970 date, I think.

My question: /how/ do I go through the Python direction I've created to
remove the pre-1970 date objects? Ideally, I would be able to iterate
through the dict and remove any DateTime objects that cause int() to fail.
Unfortunately, the DateTime error causes my script to abort entirely.

Ex:
report["COMPANY X"][1][2]

<DateTime object for '1969-12-31 00:00:00.00' at a1e1548>

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sorisio, Chris wrote:
Ladies and gentlemen,

I've imported some data from a MySQL database into a Python dictionary.
I'm attempting to tidy up the date fields, but I'm receiving a
'mx.DateTime.Error: cannot convert value to a time value' error. It's
related to glibc returning an error to a pre-1970 date, I think.
You don't say why you think this, though, which might help - when you
say you are "attempting to tidy up" the date fields, do you mean convert
them into time.time format, or what?
My question: /how/ do I go through the Python direction I've created to
remove the pre-1970 date objects? Ideally, I would be able to iterate
through the dict and remove any DateTime objects that cause int() to
fail. Unfortunately, the DateTime error causes my script to abort entirely.
Ah, I see. Well, this gives us a bit more of a clue: it's the int() of
an mx.DateTime object that throws up this error? [pauses to install
mx.DateTime ...]
Ex:
>>> report["COMPANY X"][1][2] <DateTime object for '1969-12-31 00:00:00.00' at a1e1548>

import mx.DateTime as dt
d = dt.DateTimeFrom("1969-12-31 00:00:00.00")
d <DateTime object for '1969-12-31 00:00:00.00' at a0f2ca0> int(d) -68400

Hmm, are we using different versions of Python? (This was on Cygwin
2.3.3 with mx.DateTime from mxBase-2.0.5).
Anyway, now I seem to be more or less in the same position as you.
Clearly your system has mx.DateTime loaded (at least indirectly)
otherwise your dtabase couldn't have created those ms.DateTime objects.
It's not much of a problem to install if you don't have it loaded.

So, during initialization, have your program set the epoch:
epoch = dt.DateTimeFrom("1970-01-01 00:00:00")
epoch <DateTime object for '1970-01-01 00:00:00.00' at a07ef60>

And then just compare the DateTimes to the epoch to decide whether they
can be used or not.
if d < epoch: .... print "Throw this one away"
....
Throw this one away


Perhaps you aren;t getting that error for the reason you suppose,
however, in which case a little more information would be helpful.

regards
Steve
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.