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();
console.log(results);

You can check out the docs here to learn more about queries:
https://docs.moralis.io/queries#query-constraints

2 Likes

Hi,

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!

2 Likes

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