我有一个名为 Order 的表,包含 3 列(id、date、price)。我正在尝试检索date >= startdate AND date <= endDate
. 列date
中的日期保存为TEXT
以下格式:"MM-dd-yyyy HH:mm:ss"
( 10-27-2013 12:12:43
)
我尝试了以下 SQL 语句:
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " >= DATETIME ("+ startDate + ") AND " +
PizzeriaDatabase.CELL_ORDER_DATE + " <= DATETIME(" + endDate + ")", null, null);
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " between ( " + startDate + " AND " + endDate + ")", null, null);
但是他们都抛出了同样的异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.vongrad.pizzeria/presentationLayer.ViewOrder}:
android.database.sqlite.SQLiteException: near "14": syntax error: ,
while compiling: SELECT * FROM orders WHERE (date >= DATETIME(10-27-2013 14:01:53) AND date <= DATETIME(10-27-2013 14:01:53))
所以我想我以错误的格式比较日期?