Mysql 使用sequelize nodejs仅查询当前月份
如何仅查询当月数据。 我现在使用这个查询Mysql 使用sequelize nodejs仅查询当前月份,mysql,node.js,npm,sequelize.js,Mysql,Node.js,Npm,Sequelize.js,如何仅查询当月数据。 我现在使用这个查询 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
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
选项中的sequelize.literal
,并使用以下条件将某个日期的月份第一天与当前日期的月份第一天进行比较:
(DATE_SUB(check_in,INTERVAL DAYOFMONTH(d)-1 DAY)=DATE_SUB(CURDATE(),INTERVAL DAYOFMONTH(d)-1 DAY))