datetime problems select from MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ZoombyWoof

    #1

    datetime problems select from MySQL

    Hi. I have ran into a weird thing I just can't find any solution for. I
    have googled and searched but no luck.

    The problem is that when I select TIME values from MySQL from python, I
    get wrong results when the TIME values are negative.

    From mysql program:
    mysqlselect id,flex from Users where id=2;
    +----+----------+
    | id | flex |
    +----+----------+
    | 2 | 00:30:00 |
    +----+----------+

    From python script:
    SELECT id,flex FROM Users WHERE id=2
    Data back from MySQLdb:
    ((2L, datetime.timede lta(0, 1800)),)

    This looks good and fine, but this :

    From mysql program:
    mysqlselect id,flex from Users where id=2;
    +----+-----------+
    | id | flex |
    +----+-----------+
    | 2 | -00:30:00 |
    +----+-----------+

    From python :
    SELECT id,flex FROM Users WHERE id=2
    Data back from MySQLdb:
    ((2L, datetime.timede lta(0, 1800)),)

    Not good, python thinks this is a positive value. One more:

    mysqlselect id,flex from Users where id=2;
    +----+-----------+
    | id | flex |
    +----+-----------+
    | 2 | -01:30:00 |
    +----+-----------+

    Python :
    SELECT id,flex FROM Users WHERE id=2
    Data back from MySQLdb:
    ((2L, datetime.timede lta(-1, 84600)),)

    At least its negative but this looks to me as -00:30 rather than
    -01:30..... (86400-84600 = 1800, = 30 minutes)

    And now a negative that works!:

    mysqlselect id,flex from Users where id=2;
    +----+-----------+
    | id | flex |
    +----+-----------+
    | 2 | -10:00:00 |
    +----+-----------+

    Python:
    SELECT id,flex FROM Users WHERE id=2
    Data back from MySQLdb:
    ((2L, datetime.timede lta(-1, 50400)),)

    This looks alright to me...(86400-50400 = 36000, = 10 hours)

    Any ideas ? Have I missed something obvious here or ? It seems to be
    offset by an hour or something....

    I run python2.4 on debian sarge, MySQL 5.0.18 and python-mysqldb version
    1.2.1-c2-1

    Any help greatly appreciated. Thanx.

    /ZW


Working...