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

Discussion in 'Python' started by Sorisio, Chris, Apr 23, 2004.

  1. 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>
    Sorisio, Chris, Apr 23, 2004
    #1
    1. Advertising

  2. Sorisio, Chris

    Steve Holden Guest

    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
    Steve Holden, Apr 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    686
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    520
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    374
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    328
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    744
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page