You noted that the values can sometimes be stored without the leading zero (e.g. 1:00:12
). This creates problems.
SQLite does not have special date/time data types. It allows date/time values to be stored in the basic types like TEXT
(more info), but then it expects them to be in one of the predefined formats only. There is HH:MM:SS
in the list, but no H:MM:SS
, so it would never understand your values, even if you used some date/time functions:
sqlite> SELECT TIME('12:34:56');
12:34:56
sqlite> SELECT TIME('2:34:56');
But you don't actually need to make SQLite understand your values here. If you pad them correctly (when inserting, by an UPDATE
, or dynamically during the SELECT
), it will work even without using any functions, because plain string comparisons are enough:
SELECT * FROM table WHERE SUBSTR('0'||time_happens,-8,8) > '03:00:00';
Note I needed to use the SQLite padding workaround.
Also you will still get the unpadded values in the result.