我正在尝试使用 MySql 数据库中的 Sequelize 获取两个日期之间的所有值。但是,我没有得到包含结束日期的值,除非我使用后天作为结束日期。
如何在结果中包含结束日期?
示例:如果我在 2021 年 1 月 4 日上午 07:00 到 2021 年 1 月 5 日下午 05:00 之间搜索,我只会得到 1 月 4 日的值,但是如果我在 2021 年 1 月 4 日上午 07:00 到 1 月 6 日之间搜索, 2021 年 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;
提前致谢。
最佳答案
我在前端发现了错误。我只发送日期而不是时间。一旦我将日期和时间发送到后端,就会正确返回值,包括结束日期和时间值。
关于mysql - 如何使用 Sequelize 获取位于两列之间的日期/时间,包括开始日期和结束日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65645959/