OrmLite where 子句和 SQL 与 java.util.date 之间
我尝试创建一个带有 where 子句的查询,该子句在日期之间进行过滤。我的查询看起来像
java.util.Date date1 = ...
java.util.Date date2 = ...
where().between("datefield", date1, date2)
但它不起作用。我正在使用 QueryBuilder
构建查询,并使用 selectRaw(...)
和 queryRaw(...)
。有人可以帮忙吗?
I try to create a query with a where clause which filters between dates. My query looks something like
java.util.Date date1 = ...
java.util.Date date2 = ...
where().between("datefield", date1, date2)
But it doesn't work. I am building my query with the QueryBuilder
and I use selectRaw(...)
and queryRaw(...)
. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这行不通,因为在 Android 下,
Date
字段被保存为字符串,在使用 SQLBetween
时,这些字符串无法正确比较。解决此问题的一种方法是将您的Date
字段存储为 long:这会将
Date
存储为纪元毫秒长数字,该数字具有可比性并且可与 <代码>之间。Yeah, this isn't going to work because under Android,
Date
fields are being persisted as strings which don't compare right when using SQLbetween
. One way to fix this would be to store yourDate
fields as longs instead:This will store the
Date
as the epoch milliseconds long number which is comparable and which will work withbetween
.