Search code examples
javascriptdatereact-nativerealm

How to query by date in react realm?


I have a table called visitDetails, which I'm querying as follows,

realm
.objects("visitDetails")
.filtered("visitDate='"+new Date(response.date)+"' AND chemistId='"+response.chemist_id+"'");

I have saved the visitDate as date objects before, so I'm also querying by date objects. I'm however, getting as error saying,

Error: You must pass in a date argument to compare

But I'm already passing in a date argument...

new Date( response.date )

, where response.date is in milliseconds.


Solution

  • Right now you are casting the Date object to a string by concatenate it with a string. You should do something like this

    realm.objects('visitDetails').filtered(
      "visitDate = $0 AND chemistId = $1",
      new Date(response.date),
      response.chemist_id
    );