datetime problems select from MySQL

Z

ZoombyWoof

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:
mysql> select 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:
mysql> select 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:

mysql> select 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!:

mysql> select 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top