[英]Filter date not between two dates
Using Realm 2.7.0
and Swift 3
, my application tries to filter a object based on its date, returning all dates that are NOT between two given dates. 使用
Realm 2.7.0
和Swift 3
,我的应用程序尝试根据对象的日期过滤对象,返回不在两个给定日期之间的所有日期。
Given a Object
called Model
, it has an variable called date (type NSDate
). 给定一个名为
Model
的Object
,它具有一个称为date的变量(类型NSDate
)。
Currently, I am using this code to filter: 目前,我正在使用以下代码进行过滤:
realm.objects(Model.self)
.filter("NOT date BETWEEN %@", [today, twoDaysAgo])
But it is returning all data, the filter is not working. 但是它返回所有数据,筛选器不起作用。
Thank you. 谢谢。
Try this 尝试这个
realm.objects(Model.self)
.filter("NOT (date BETWEEN %@)", [today, twoDaysAgo])
try this predicate query 试试这个谓词查询
let predicate = NSPredicate(format: "!(date BETWEEN %@ , %@)", today, twoDaysAgo) let谓词= NSPredicate(格式:“!(日期%@,%@)之间,今天,两天前)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.