Query MongoDB documents for a particular date range

Hi devs, I am trying to query documents based on particular date range. So I need all the documents where the createdDate is less than equal to current date and greater than equal to currentDate - 2. I am assuming that there is some issue in the date format between how mongo db stores and how I am trying to fire that in the query. Attached the screenshot. Can someone help
No description
No description
No description
3 Replies
glutonium
glutonium6mo ago
hage u tried console logging the 2 dates? and see if they r correct of not?
SpongeBob
SpongeBobOP6mo ago
With previous code I was not getting that format which I was seeing in mongoDB so I tried to tweak the code little bit. Still not seeing the correct date after consoling.
No description
SpongeBob
SpongeBobOP6mo ago
I read it somewhere that I have to convert these into UTC format using ISOString method so I tried that.
Want results from more Discord servers?
Add your server