Pedro Palermo
Pedro Palermo

Reputation: 43

How to filter by hour from DataTime using sqlite?

My table has several fields and one of then is a DateTime, called date, in format 'YYYY-MM-DD hh:mm:ss' and runs with SQLite3. I would like to display all the costumers that came between 8 and 15. Here is my code so far:

SELECT *
  FROM Clients
WHERE TIME(date) > strftime('%H','08') AND TIME(date) < strftime('%H','15');

Right now it does not display anything.

Any suggestions ?

Upvotes: 0

Views: 193

Answers (1)

FDavidov
FDavidov

Reputation: 3675

Try this:

SELECT *
  FROM Clients
 WHERE CAST(strftime('%H' , date) AS INT) > 8  AND 
       CAST(strftime('%H' , date) AS INT) < 15       ;

Upvotes: 1

Related Questions