0 Follower 0 Following Follow. Convert seconds to hh:mm:ss in Python [duplicate] Ask Question Asked 10 years, 11 months ago. Tech Sign In Page Forgot Password? See calendar. This question already has answers here: How do I convert seconds to hours, minutes and seconds? share this SD. Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunitiesSELECT CONVERT(varchar, DATEADD(ms, 121.25 * 1000, 0), 114) is it.This won't work if you have more than 24 hours worth of secondsVery neat. Forum: Search: FAQs: Links: MVPs: Menu. How do I convert an int (number of seconds) to the formats I need to do this with Python code (and if possible in a Django template).I can't believe any of the many answers gives what I'd consider the "one obvious way to do it" (and I'm not even Dutch...!-) -- up to just below 24 hours' worth of seconds (86399 seconds, specifically):Doing it in a Django template's more finicky, since the Depending on your exact needs, it might be more convenient to define a custom filter for this formatting task in your app.Code that does what was requested, with examples, and showing how cases he didn't specify are handled:You can--and probably should--store this as a timedelta rather than an int, but that's a separate issue and timedelta doesn't actually make this particular task any easier.SilentGhost's answer has the details my answer leaves out and is reposted here:You can calculate the number of minutes and hours from the number of seconds by simple division:If you use divmod, you are immune to different flavors of integer division:Just be careful when dividing by 60: division between integers returns an integer -> In HH:MM:SS, '51:03:20' is not valid. Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunities

The situation is you have a value in Seconds (XXX.XX), and you want to convert to HH:MM:SS using T-SQL.You want to multiply out to milliseconds as the fractional part is discarded.If you want it without the date portion you can use CONVERT, with style 114The following function will handle times exceeding 24 hours (~max 35,791,394 hours).For those having issues with using DATEADD and CONVERT for seconds exceeding 24 hours, we can use modulus to get around that:Using SQL Server 05 I can get this to work by using:This is what I use (typically for html table email reports)Thanks for contributing an answer to Stack Overflow! Stack Overflow works best with JavaScript enabled

The following is copy and pasted from Python 2.6.2:If you need to do this a lot, you can precalculate all possible strings for number of seconds in a day:Now conversion of seconds to format string is a fast indexed lookup:Not being a Python person, but the easiest without any libraries is just:Besides the fact that Python has built in support for dates and times (see bigmattyh's response), finding minutes or hours from seconds is easy:Now, when you want to display minutes or seconds, MOD them by 60 so that they will not be larger than 59
The question how to convert it to HH:MM:SS … Convert seconds to hours and minutes BobH90024 Sep 16, 2009 4:13 PM Hi, I have a column which stores elapsed time in seconds.

The start time I have is in time format. And it's much easier to just convert to string and be happy with His question doesn't look fluid to me; it asks how to convert seconds to two specific formats, and almost everyone is responding with answers that simply don't do what he asked. The Overflow Blog You will have to split it up into individual pieces, multiplying by the conversion factor to get to seconds. Convert seconds to days , hh:mm:ss C#. Editing the string means you're depending on the specific behavior of timedelta's string formatting (if s[0:2] == "0:": ...), which is a bad idea. With the below function I could convert it to 3.02:05:45. (12 answers) Closed 6 years ago.