java - Querying the Month part of a date in SQLite
问题描述
I can query year part of a date using String [] selectionArgs = { "2018" };
String query =
"SELECT * FROM TABLE" +
"WHERE strftime('%Y', COLUMN_DATE) = ?" +
"ORDER BY strftime('%m', COLUMN_DATE) DESC;"
return db.rawQuery(query, selectionArgs);
But I am having trouble querying the month part of the date like I did for the year part.
Can someone help me?
解决方案
If you want the date to have a specific month (without having constraints on the year or the date), you can continue to use the strftime
function. Querying results for October:
WHERE strftime('%m', COLUMN_DATE) = '10' /* October */
If you want to query results for a specific month-year, you can combine both of them like this:
WHERE strftime('%Y-%m', COLUMN_DATE) = '2011-05' /* May, 2011 */
推荐阅读
- android - 我将我的 android studio 和 gradle 更新到了最新版本 -> 我无法使用数据绑定
- hex - 使用校验和通过 ASCII 将消息从设备转换为 LIS
- python - 使用 Python 打印 Power Point 幻灯片编号
- java - junit : 获取 CompletableFuture 的方法
永不回来 - html - 如何使用 Selenium 和 Python 中的兄弟关系以最可靠的方式从 div 中读取文本列表?
- angular - 选择中的角度显示数据
- nginx - Nginx - 从上游读取响应标头时主脚本未知
- amazon-web-services - 跨区域代码部署错误。(AWS Codepipeline)
- arrays - 如何从matlab中的二维数组中检索值?
- spotfire - spotfire 数据功能:表的输入参数不包括数据表的所有列