I'm performing a database query from a Flutter application in which I need to bring records in the period between two dates. However, the query does not return records even though there are records saved for this period.
The query below returns zero records:
final List<Map<String, dynamic>> records = await db.rawQuery(
'SELECT * FROM vehicles WHERE created BETWEEN 2022-07-17 AND 2022-08-16');
Attempting not to use the BETWEEN clause as below did not work either
final List<Map<String, dynamic>> records = await db.rawQuery(
'SELECT * FROM vehicles WHERE created >= 2022-07-17 AND created <= 2022-08-16');
I also emphasize that the "created" column of the "vehicles" table stores String dates in the following format: YYYY-MM-DD and that the console does not report any syntax errors, it just does not working
I guess the problem is that you haven't added quotes in date. So it should look like this:
final List<Map<String, dynamic>> records = await db.rawQuery(
"SELECT * FROM vehicles WHERE created BETWEEN '2022-07-17' AND '2022-08-16'");
or like this:
final List<Map<String, dynamic>> records = await db.rawQuery(
"SELECT * FROM vehicles WHERE created >= '2022-07-17' AND created <= '2022-08-16'");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.