Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5471 > unrolled thread

Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class

Started byChris Angelico <rosuav@gmail.com>
First post2011-05-16 13:50 +1000
Last post2011-05-16 13:50 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class Chris Angelico <rosuav@gmail.com> - 2011-05-16 13:50 +1000

#5471 — Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class

FromChris Angelico <rosuav@gmail.com>
Date2011-05-16 13:50 +1000
SubjectRe: MySQLdb SEC_TO_TIME function returns datetime.timedelta class
Message-ID<mailman.1615.1305517814.9059.python-list@python.org>
On Mon, May 16, 2011 at 10:42 AM, Jorge Romero <jorgeromero178@gmail.com> wrote:
> Hi Pythonists,
> I'm retrieving some time data from a MySQL database using Python's MySQLdb
> library. Here's the situation, I got a time field on MySQL given in seconds,
> I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME
> function, something like this:
> query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table"

You're summing a column, so presumably the values are actually deltas
(it doesn't make sense, for instance, to add Tues March 16th to Sat
Nov 2nd). The result exceeds a day; in what format do you actually
want it?

For maximum flexibility, you could ditch the SEC_TO_TIME call and
simply work with the integer seconds in Python. You can then format
that into HHHHH:MM:SS or whatever suits you.

Chris Angelico

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web