472,331 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 1854

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Terry Hancock | last post by:
What do you do when a date or time is incompletely specified? ISTM, that as it is, there is no formal way to store this --- you have to guess, and...
0
by: Andy Jackman | last post by:
Hi, 1) I was investigating the unix_timestamp routine in mysql (version 3.23.46-nt) and for some reason the unix epoch (1-1-1970) was returned...
0
by: Jim S. | last post by:
I'm having a horrible time simply inserting the date in a MySQL database through a Visual Basic program. I have a table, called "ORDERS"; "ID" is...
6
by: Thomas Bartkus | last post by:
MySQL Version 4.0.20 on a Linux server. How does one get the elapsed time between (2) DateTime values? I need the answer to the nearest minute. ...
1
by: Propel Exacto | last post by:
Hey guys, I am using MySQL 4.0.18 and I have a field named "order_datetime" in which I store data in the format 20041001 23:00:00 (for example...
2
by: Kenneth P | last post by:
Hi, I'm trying to use MySql 4.1 db instead of MSSql2k and am having problems with the DateTime in the db. In mysqladmtools 1.0.19 I'm...
1
by: Mike the Canadian | last post by:
Suppose I have a MySQL 5 table with a DateTime field in it. The table has two records where the time is blank. Running: SELECT CAST(DateTimeField...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on...
2
by: electronik | last post by:
I dont really have a problem, but I want to make my code faster and prettier. I have some tables with DATETIME in it. They have the std format...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.