mx.DateTime.Error: cannot convert value to a time value
sholden at holdenweb.com
Sun Apr 25 17:02:10 CEST 2004
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
> >>> report["COMPANY X"]
> <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")
<DateTime object for '1969-12-31 00:00:00.00' at a0f2ca0>
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")
<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.
More information about the Python-list