Search code examples
sqlitetimemillisecondsseconds

how to do sec_to_time in SQLite?


I have a field with seconds after midnight, and I have to convert it to HH:MM:SS. MySQL has sec_to_time(), which would be perfect, but SQLite does not.

How to convert?

I feel like it's some combination of strftime or date, and some dividing by 3600, but I can't get it.

For example, I need to convert 3601 to 1:01. Or, 32405 -> 9:05.


Solution

  • Use time()

    select time(3601, 'unixepoch');
    

    will give:

    01:00:01