Query last day, last week, last month SQLite Query last day, last week, last month SQLite database database

Query last day, last week, last month SQLite


I have found this solution. I hope it works for you.

For last day:

SELECT * FROM statistics WHERE date BETWEEN datetime('now', 'start of day') AND datetime('now', 'localtime');

For last week:

SELECT * FROM statistics WHERE date BETWEEN datetime('now', '-6 days') AND datetime('now', 'localtime');

For last month:

SELECT * FROM statistics WHERE date BETWEEN datetime('now', 'start of month') AND datetime('now', 'localtime');


This code should get you the previous month

SELECT * FROM statistics WHERE date >= date('now','start of month','-1 month')AND date < date('now','start of month')


SELECT * FROM statistics WHERE date >= date('now','start of month','-1 months')AND date < date('now','start of month')

On more months, is "months" and not month like as other said before.