469,909 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

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.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
Aug 24 '06 #1
0 1785

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Terry Hancock | last post: by
reply views Thread by Andy Jackman | last post: by
6 posts views Thread by Thomas Bartkus | last post: by
2 posts views Thread by Kenneth P | last post: by
1 post views Thread by Mike the Canadian | last post: by
5 posts views Thread by iulian.ilea | last post: by
2 posts views Thread by electronik | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.