Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5471
| References | <BANLkTimRx5oc+iRfxDDEe7R-UR30H8R=ZQ@mail.gmail.com> |
|---|---|
| Date | 2011-05-16 13:50 +1000 |
| Subject | Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1615.1305517814.9059.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class Chris Angelico <rosuav@gmail.com> - 2011-05-16 13:50 +1000
csiph-web