On Aug 8, 2006, at 5:03 AM, Simen Haugen wrote:

Running a timediff thru a cursor to a mysql db returns another result
than running the query on the database directly. It seems the problem
only exists when it's a negative value:

mysql> select timediff("2006-08-08 10:00:00", "2006-08-08 11:00:00") as
tid;
+-----------+
| tid       |
+-----------+
| -01:00:00 |
+-----------+
1 row in set (0.00 sec)


biz = self.getBizobj()
crs = biz.getTempCursor()
crs.execute(""" select timediff("2006-08-08 10:00:00", "2006-08-08
11:00:00")  as tid""")
ds = crs.getDataSet()
print ds[0]["tid"]
-1 day, 23:00:00

I think it is a function of how a timedelta value represents itself as a string.

>>> biz = self.getBizobj()
>>> crs = biz.getTempCursor()
>>> crs.execute(""" select timediff("2006-08-08 10:00:00", "2006-08-08
         11:00:00")  as tid""")
1L
>>> ds = crs.getDataSet()
>>> print ds[0]["tid"]
-1 day, 23:00:00
>>> ds
({'tid': datetime.timedelta(-1, 82800)},)
>>> ds[0]["tid"]
datetime.timedelta(-1, 82800)

Note that calling 'print' and just entering the name of the value result in two different outputs. Here's another example, using just Python's datetime module:

>>> import datetime
>>> t=datetime.timedelta(-1)
>>> t
datetime.timedelta(-1)
>>> print t
-1 day, 0:00:00


-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to