如何使用 Sequelize 获取包含开始日期和结束日期在内的两列之间的 dates/times

How to get dates/times that fall between two columns including start and end dates using Sequelize

我试图在 MySql 数据库中使用 Sequelize 获取两个日期之间的所有值。但是,我没有得到包含结束日期的值,除非我将后一天用作结束日期。 如何在结果中包含结束日期?

示例:如果我在 2021 年 1 月 4 日 07:00 上午和 2021 年 1 月 5 日 05:00 下午之间进行搜索,我只会得到 1 月 4 日的值,但是如果我在 1 月 4 日之间进行搜索, 2021 07:00 am 和 2021 年 1 月 6 日 05:00 pm 我都可以看到,1 月 4 日和 1 月 5 日。 我正在使用 Op.lte 和 Op.gte 运算符,但不知道我在这里遗漏了什么。

这是我的快递路线:

const express = require("express");
const router = express.Router();
const PunchClock = require("../models").PunchClock;
const Employee = require("../models").Employee;
const { Op } = require("sequelize");

router.get("/all_dates/:id/:dateStart/:dateEnd", (req, res) => {
  Employee.findOne({
    where: {
      id: req.params.id,
    },
    include: {
      model: PunchClock,
      where: {
        punchInTime: { [Op.gte]: req.params.dateStart },
        punchOutTime: { [Op.lte]: req.params.dateEnd },
      },
    },
  })
    .then((employee) => {
      res.json(employee.PunchClocks);
    })
    .catch((err) => res.json(err));
});

module.exports = router;

提前致谢。

我发现了前端的错误。我只发送日期而不是时间。一旦我将日期和时间发送到后端,正确返回的值包括结束日期和时间值。