How would you convert secs to HH:MM:SS format in SQLite?
To convert seconds to HH:MM:SS :Multiply the seconds by 1000 to get milliseconds.
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.
strftime('%H:%M:%S', time.
Try this one:
sqlite> SELECT time(10, 'unixepoch');
00:00:10
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With