使用 sequelize nodejs 仅查询当前月份

query only current month using sequelize nodejs

如何只查询当月数据。 我现在使用这个查询。

  app.get("/api/timesheet_employerId", function (req, res) {
    console.log("I am the employerId", req.user.id)
    db.TimeSheet.findAll({
      include: [
        'employee'
      ],
      order: [['check_in', 'DESC']],
    }).then(function (results) {
      let filtered_result = results.filter(element => element.employee.EmployerId === req.user.id);
      res.json(filtered_result);
    });
  });the

您应该在 where 选项中使用 seqeulize.literal 并使用条件比较特定日期的月份的第一天和当前日期的月份的第一天:

(DATE_SUB(check_in,INTERVAL DAYOFMONTH(d)-1 DAY)=DATE_SUB(CURDATE(),INTERVAL DAYOFMONTH(d)-1 DAY))