Home >Database >Mysql Tutorial >Why Does My SQLite Query Return All Dates Instead of the Specified Range?
SQLite date range query error: resolved
When using SQLite to generate a sales report, the query results return all dates instead of dates within the specified range. The following is the query code used:
<code class="language-sql">SELECT * FROM test WHERE date BETWEEN "11/1/2011" AND "11/8/2011";</code>
Cause of the problem:
SQLite requires dates to be in YYYY-MM-DD format. However, dates and query strings in the database do not follow this format. Therefore, SQLite interprets "date" as a string rather than a date.
Solution:
To resolve this issue, ensure that both the date and query string in the database conform to YYYY-MM-DD format. The correct query should look like this:
<code class="language-sql">SELECT * FROM test WHERE date BETWEEN "2011-11-01" AND "2011-11-08";</code>
The above is the detailed content of Why Does My SQLite Query Return All Dates Instead of the Specified Range?. For more information, please follow other related articles on the PHP Chinese website!