Reputation: 1858
I am using SQLite in Android to store a timeStamp in this format: yyyy-MM-dd HH:mm:ss
I would like to compare just the time of the timestamp with some values eg. HOUR(timestamp)>12
etc. , but HOUR is not a legal function in SQLite. I have changed it as described below and I have something like this: " where "+" strftime('%H','"+timeStamp+"')>"+time1+" AND strftime('%H','"+timeStamp+"')<'"+time2;
where time1 and time2 are integer between 0-23. I have 7 entries in the table so 7 timestamps. however i get 0 results back...
Upvotes: 2
Views: 1305
Reputation: 3569
If the timestamp is in the table you want something like:
String time1 = 0;
String time2 = 12;
String query = "select timestamp from table where strftime('%H',timestamp) < " +
time1 +
" and strftime('%H',timeStamp) < " +
time2 +
";";
Upvotes: 1
Reputation: 16512
You can try
SELECT strftime('%H', 'now');
or
SELECT strftime('%H', columnName);
the output will be 0 to 24
Upvotes: 3