Query date field

Do you have any examples how to query date field?
I tried something like this but seems that doesn’t work, no error but date is not filtered.

const tokenResult = await inTokenQuery.find({ “updatedAt” : { $gte : new Date(2021,5,11,0,0,0).toISOString(), $lt : new Date(2021,5,12,0,0,0).toISOString() }})

Hi Marta,

Here’s an example that could be run in the JavaScript console. It’s much easier to use the built in query filters. The mongo DB syntax only applies to the pipleline when using aggregate queries.

const query = new Moralis.Query("EthTransactions")
  .greaterThan("block_timestamp", new Date(2020, 2, 1))
  .lessThan("block_timestamp", new Date(2020, 3, 1));
const results = await query.find();

You can check out the docs here to learn more about queries:



Thanks for the replay but seems that query date doesn’t work. I used your example in JS console and there is no result even if there are valid data in the database table EthTransactionTokens,

![Screenshot 2021-05-14 at 11.28.47|690x312] Do I still using it wrong?

Details of my table EthTokenTransfers, there are items with date greater than 13.05.2021

The JavaScript devs must’ve been drunk or sleep deprived when they created the Date object because the Month is zero indexed!.. so the above query is checking for dates in June not May!


this is also not working for me. any updates or solutions on this? @Marta