Connecting Tech Pros Worldwide Forums | Help | Site Map

datetime problems select from MySQL

ZoombyWoof
Guest
 
Posts: n/a
#1: Aug 24 '06
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.timedelta(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.timedelta(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.timedelta(-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.timedelta(-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



Closed Thread