Search code examples
sqliteselectfilterstrftime

sqlite select where field time


I have an sqlite table as follow: enter image description here I have to select the rows where 'start'< now time in order to have just the ongoing program; logically as: if time now is 10:05 then the result should be: enter image description here How I can formulate the right select statement? Thank u in advance for any help.


Solution

  • You can use the function strftime() to get the current time in the format HH:MM so that you can compare it to the column start:

    SELECT *
    FROM tablename
    WHERE start < strftime('%H:%M', 'now');
    

    If you want only the last row for each dpt:

    SELECT *
    FROM tablename
    WHERE start < strftime('%H:%M', 'now')
    GROUP BY dpt
    HAVING MAX(start);