android sqlite中String日期查询转换操作,sqlite日期查询
如果表结构是Date类型比较好办直接操作就可以了这个不多说;
如果表结构是String类型则需要在查询时把要查找的字段转换为Date来和其他的日期比较后作为查询条件
Cursor mCursor = db.query(true, DATABASE_SLEEP_TABLE,
new String[] { KEY_SLEEP_ROWID, KEY_SLEEP_START_DATE,
KEY_SLEEP_END_DATE, KEY_SLEEP_DEEPSLEEP,
KEY_SLEEP_LIGHTSLEEP, KEY_SLEEP_ONLINE },
" **strftime('%s', "+KEY_SLEEP_END_DATE+")** BETWEEN strftime('%s', '"+normalStartDate+"') AND strftime('%s', '"+normalEndDate+"') " +
"and strftime('%s', "+KEY_SLEEP_START_DATE+") BETWEEN strftime('%s', '"+normalStartDate+"') AND strftime('%s', '"+normalEndDate+"')"
+"or strftime('%s', "+KEY_SLEEP_START_DATE+")<= strftime('%s', '"+normalStartDate+"')" +
" and strftime('%s', "+KEY_SLEEP_END_DATE+") BETWEEN strftime('%s', '"+normalStartDate+"') AND strftime('%s', '"+normalEndDate+"') "
+" or strftime('%s', "+KEY_SLEEP_END_DATE+")>=strftime('%s', '"+normalEndDate+"')" +
"and strftime('%s', "+KEY_SLEEP_START_DATE+") BETWEEN strftime('%s', '"+normalStartDate+"') AND strftime('%s', '"+normalEndDate+"')" ,
null, null, null, null, null);
strftime(‘%s’, “+KEY_SLEEP_END_DATE+”)就是把String字段转变为日期Date来进行比较操作
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。