I want to convert sqlite query to Ormlite query.
SELECT * FROM Test where strftime('%m-%Y',Date)='11-2001'
I could not format date column like above query.
How to format Date column in Ormlite as MM-yyyy
?
Thanks.
I want to convert sqlite query to Ormlite query.
SELECT * FROM Test where strftime('%m-%Y',Date)='11-2001'
I could not format date column like above query.
How to format Date column in Ormlite as MM-yyyy
?
Thanks.
如果那是您要使用的确切 SQL,那么您可以使用以下Where.raw(...)
方法:
QueryBuilder<Test, Integer> qb = testDao.queryBuilder();
qb.where().raw("strftime('%m-%Y',Date) = '11-2001'");
List<Test> results = qb.query();
但是,这似乎仅在日期字段存储为DATE_STRING
类型时才有效:
@DatabaseField(dataType = DataType.DATE_STRING)
Date date;
问题是默认情况下 Xerial JDBC 驱动程序以以下格式存储日期:
2012-07-19 09:58:18.36
哪个不 [相当] 匹配已批准的 Sqlite 格式之一,这些格式是:
当您将其更改为DataType.DATE_STRING
then 时,它将按以下方式存储,这似乎可行:
2012-07-19 10:03:49.000991
有关详细信息,请参阅有关日期函数的 Sqlite 文档。不幸的是,文档没有完全解释数据库值需要采用某种格式: