首页 > 解决方案 > Android Sqlite 通过“selection”和“selectionArgs”搜索日期

问题描述

我使用类似于以下代码的代码在两个日期之间搜索数据库:

cursor.query(select column from Table where columnDate between '2018-09-20' and '2018-09-23');

但现在我想使用 queryprojection和.selectionselcetionArgs

如何更新我的代码?

标签: androidsqliteandroid-sqlite

解决方案


你可以使用这个:

cursor.query("Table" ,
    new String[]{"column"},
    "columnDate BETWEEN ? AND ?", 
    new String[]{"2018-09-20","2018-09-23"},
    null/*Group by if you need*/,
    null/*having if you need*/,
    null/*order by if you need*/);

推荐阅读