Home > Mobile >  problem getting route that base on between two date
problem getting route that base on between two date

Time:10-20

guys, i want to get a range between two dates the date is getting from the user and show the task that he made in this range for that i need to get this date and router to it but I failed to get it. i get this URL that form give

http://localhost:3001/home/range?from=2022-08-31&to=2022-10-26 this is my route

router.get("/range", ensureAuth, homeController.getRange);

this my controller

getRange: async (req, res) => {
    let from = req.query.from;
    let to = req.query.to;
    console.log(from);
    // try this 
    console.log(req.params.from);
    console.log(req.params.to);
    //and this
    console.log(req.body.from);
    console.log(req.body.to);

    let tasks = await Tasks.find({
      day: {
        $gt: new Date(moment(from, "YYYY/MM/DD").format()),
        $lt: new Date(moment(to, "YYYY/MM/DD").format()),
      },
      user: req.user.id,
    });

    res.render("dashboard.ejs", {
      tasks: tasks,
      title: "range filter",
      user: req.user,
    });
  },
    <form action="/home/range" method="get" >
         <div >
            <div >
               <label for="from">From</label>
               <input type="date" name="from" id="from">
            </div>
            <div >
               <label for="to">From</label>
               <input type="date" name="to" id="to">
            </div>
         </div>

         <button type="submit">Go</button>
      </form>

CodePudding user response:

try this one bro

    let from = req.query.from;
    let to = req.query.to;
    let tasks = await Tasks.find({
      day: {
        $gt: from,
        $lt: to,
      },
      user: req.user.id,
    });

https://mongoplayground.net/p/4bFOsEF4ZXf

  • Related