title: Finding data between two dates by using a query in mongoose
body: <p>How would I write a query which checks the createdAt and finds all objects between 2022-05-22 and 2022-06-22? I tried the following code/ API, but it didn’t give back the right data :</p>
  <pre><code>getPoDetails = async (req, res, next) =&gt; {
      try {
          let fromDate = req.query.fromDate;
          let toDate = req.query.toDate;
          var findQry = {};
          if(fromDate &amp;&amp; toDate) {
              findQry.createdAt = {$gte: new Date(fromDate), $lte: new Date(toDate)};
          }
          allmodels.poDetailsModel.find(findQry)
          .then(data =&gt; res.status(200).send(data))
          .catch(err =&gt; res.status(400).send(err));
      } catch (error) {
          next(error);
      }
  }
  </code></pre>
  <p>API link : localhost:8000/getPoDetails?fromDate=2022-05-22&amp;toDate=2022-06-22</p>