Search code examples
swiftrealm

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.

Given a Object called Model, it has an variable called date (type 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.


Solution

  • Try this

    realm.objects(Model.self)
      .filter("NOT (date BETWEEN %@)", [today, twoDaysAgo])