I have a table in my sqlite3 databse which has the following fields:
id text not null, phonenum text not null, timeofcall text not null
The timestamp is basically the time of the insertion (in my app when a person calls it inserts the tele number and also the time of the call.)
I want to get all of the rows for a particular number within the last minute, something like:
SELECT * FROM callstbl WHERE phonenum = '07857463756' AND timeofcall < 1 minute ago;
How is something like this accomplished?
EDIT:
when i use this query as suggest by the top poster I get back every row that matches the ‘phonenum’, its like its ignoring the time function
String sql = "select * FROM callstbl WHERE timeofcall >= datetime('now', '-1 minutes') AND phonenum='"+num+"'";
The format of my date-time string (timeofcall) is yyyy-MM-dd HH:mm:ss
if i just do
SELECT * FROM callstbl WHERE timeofcall >= datetime('now', '-1 minutes');
I get back every row in the database.
I’d suggest its better to have a column say, timeOfCallMili in your table which stores the time in Miliseconds. This way it will be much easier for you to query based on date/time.
Your query will be something like
or say you want to get the records within 7 days old (or any specific date for that matter), you could just use a Calendar object to represent that date/time.
So now your query becomes
This way you get full flexibility on any type of time based query.