<br><br><div class="gmail_quote">On Sun, May 15, 2011 at 11:50 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Mon, May 16, 2011 at 10:42 AM, Jorge Romero <<a href="mailto:jorgeromero178@gmail.com">jorgeromero178@gmail.com</a>> wrote:<br>
> Hi Pythonists,<br>
> I'm retrieving some time data from a MySQL database using Python's MySQLdb<br>
> library. Here's the situation, I got a time field on MySQL given in seconds,<br>
> I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME<br>
> function, something like this:<br>
> query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table"<br>
<br>
</div>You're summing a column, so presumably the values are actually deltas<br>
(it doesn't make sense, for instance, to add Tues March 16th to Sat<br>
Nov 2nd). The result exceeds a day; in what format do you actually<br>
want it?<br>
<br>
For maximum flexibility, you could ditch the SEC_TO_TIME call and<br>
simply work with the integer seconds in Python. You can then format<br>
that into HHHHH:MM:SS or whatever suits you.<br>
<br>
Chris Angelico<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all">Yeah, I believe that's the way to go, retrieve seconds and deal with them with Python, for flexibility as you pointed. I need the seconds to become HH:MM:SS format.<div><br>

</div><div>What seems weird to me is why MySQLdb treats the result of the query as deltas. Here's what I get if a query directly the database, output from PHP MyAdmin:<div><br></div><div><span class="Apple-style-span" style="font-weight: bold; ">SEC_TO_TIME(SUM(billsec))</span></div>

<div><b><span class="Apple-style-span" style="font-weight: normal; ">79:30:09</span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal;"><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal;">This value suits better the <i>datetime.time</i> type, instead of <i>datetime.deltatime</i>.<br>

</span></b><div><br></div><div>Thanks Chris for your feedback.</div><div><br></div><div>-- <br>Jorge Romero<br><br>
</div></div></div>