Im trying to do a SELECT * to retrieve rows for last 7 days in SQLite.
the table structure is as follows
CREATE TABLE 'session' ('rowID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'steps' INTEGER, 'stop_time' DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP)
How do I do this? Im new at this
SQLite provides two wildcards for constructing patterns. They are percent sign % and underscore _ : The percent sign % wildcard matches any sequence of zero or more characters. The underscore _ wildcard matches any single character.
The SQLite strftime function is a very powerful function that allows you to return a formatted date as well as perform date calculations on that date. This function returns the date as a text representation.
The SQLite date() function is used to calculate the date and return it in the format 'YYYY-MM-DD'. The SQLite datetime() function is used to calculate a date/time value, and return it in the format 'YYYY-MM-DD HH:MM:SS'. The SQLite julianday() function returns the date according to julian day.
SELECT * FROM session WHERE stop_time > (SELECT DATETIME('now', '-7 day'))
Refer to the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With