gpt4 book ai didi

mysql - Sequelize 如何比较日期的年份和月份

转载 作者:行者123 更新时间:2023-12-03 08:17:47 26 4
gpt4 key购买 nike

我目前有这个代码:

Evento.findAll({
where: db.sequelize.where(db.sequelize.fn('MONTH', db.sequelize.col('start_date')), req.body.month),
order: ['start_date'],
attributes: ['id', 'description', 'start_date', 'end_date', 'picture', 'status', 'place', 'text'],
include: [{
model: TypeEvent
}]
}).then(events => {
if (events) {
res.status(200).send({
events
});
} else {
res.status(400).send({
message: "without events"
});
}
});

但是我也需要咨询今年的事情,我不知道该怎么做,我已经尝试了所有方法,但我无法得到答案。

我想要的 SQL 查询:

SELECT .... FROM ... WHERE MONTH(start_date)=5 AND YEAR(start_date)=2021 ORDER BY ..

请帮帮我...

最佳答案

Evento.findAll({
where: {
[Op.and]: [
Sequelize.where(Sequelize.fn('MONTH', Sequelize.col('start_date')), req.body.month),
Sequelize.where(Sequelize.fn('YEAR', Sequelize.col('start_date')), req.body.year),
],
},
order: ['start_date'],
attributes: ['id', 'description', 'start_date', 'end_date', 'picture', 'status', 'place', 'text'],
include: [
{
model: TypeEvent,
},
],
}).then((events) => {
if (events) {
res.status(200).send({
events,
});
} else {
res.status(400).send({
message: 'without events',
});
}
});

关于mysql - Sequelize 如何比较日期的年份和月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68824860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com