SQLite Forum

Select Last 24 hours
Login
I love Keith's answer - it's 100% correct and shares exactly as much info as the question does.

I'll be the Samaritan this time and offer the following:

1. There is no way for the database to know at what physical World/Human/Clock time any data-row was added, so in that regard, there is absolutely no way of selecting data that are above or below any specific age.
2. Unless... If you've added a column/field that recorded the exact time when the row was added or the recorded event happened, then you have provided a time-based reference by which one could filter using the WHERE clause that Keith mentioned.


Since you have not given any schema and not mentioned how you store data (and which data you store), we do not know if you have such a column or store such a reference, so we can have no idea whether you would be able to filter using it.

If I was to assume that your table "table_name" DOES have such a column, perhaps called "time_added" which contains the ISO8601 format supported by SQLite, such as would be given by the function "datetime('now')" or the like, then you can construct a query like this to give the result you need:

~~~
"SELECT * FROM table_name WHERE time_added > datetime('now','-24 hour');"
~~~

The data that you added to the table would need to either have a default value set to the current date-time, or have values supplied something like this:

~~~
INSERT INTO table_name(id,time_added,...etc...) VALUES
 (1, datetime('now'), ...etc...);
~~~

To understand what I did there you may need to [read up on expressions](https://sqlite.org/lang_expr.html) and [date-time handling in SQLite](https://www.sqlite.org/lang_datefunc.html).


Next time, please be a lot more clear with your question, it will save you a lot of time waiting for someone to answer.