Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you convert secs to HH:MM:SS format in SQLite?

How would you convert secs to HH:MM:SS format in SQLite?

like image 561
vfclists Avatar asked Apr 21 '10 19:04

vfclists


People also ask

How do you convert seconds to HH MM SS?

To convert seconds to HH:MM:SS :Multiply the seconds by 1000 to get milliseconds.

How do you convert seconds to HH MM SS format in Python?

Use the timedelta() constructor and pass the seconds value to it using the seconds argument. The timedelta constructor creates the timedelta object, representing time in days, hours, minutes, and seconds ( days, hh:mm:ss.ms ) format. For example, datetime.

How do you get HH MM SS in Python?

strftime('%H:%M:%S', time.


2 Answers

Try this one:

sqlite> SELECT time(10, 'unixepoch');
00:00:10
like image 170
newtover Avatar answered Sep 19 '22 01:09

newtover


If your seconds are more than 24 hours, you need to calculate it yourself. For example, with 100123 seconds, rounding down to minutes:

SELECT (100123/3600) || ' hours, ' || (100123%3600/60) ||' minutes.'
27 hours, 48 minutes

The time or strftime functions will obviously convert every 24-hours to another day. So the following shows 3 hours (the time on the next day):

SELECT time(100123, 'unixepoch')
03:48:43

To get the full 27 hours, you can calculate the hours separately, and then use strftime for the minutes and seconds:

SELECT (100123/3600) || ':' || strftime('%M:%S', 100123/86400.0);
27:48:43
like image 36
mivk Avatar answered Sep 21 '22 01:09

mivk