I am running sqlite to select data between two ranges for a sales report. To select the data from between two dates I use the following statement:
SELECT * FROM test WHERE date BETWEEN "11/1/2011" AND "11/8/2011";
This statement grabs all the dates even those outside the criteria. The date format you see entered is in the same format that I get back. I'm not sure what's wrong but appreciate any help I can find. Thanks!
Or you can cast your string to Date format with date function. Even the date is stored as TEXT in the DB. Like this (the most workable variant):
Special thanks to Jeff and vapcguy your interactivity is really encouraging.
Here is a more complex statement that is useful when the length between '/' is unknown::
One more way to select between dates in SQLite is to use the powerful strftime function:
These are equivalent according to https://sqlite.org/lang_datefunc.html:
but if you want more choice, you have it.
Note that I use the format :
dd/mm/yyyy
If you use d/m/yyyy, Change in
substr()
Hope this will help you.
SQLLite requires dates to be in
YYYY-MM-DD
format. Since the data in your database and the string in your query isn't in that format, it is probably treating your "dates" as strings.Change your data to that formats to use sqlite datetime formats.