const { Op } = require("sequelize");
Foo.findAll({
where: {
// myDateColumn < [timestamp] AND myDateColumn > [timestamp]
{
myDateColumn: {
[Op.lt]: new Date(),
[Op.gt]: new Date(new Date() - 24 * 60 * 60 * 1000)
}
},
// myDateColumn in range
[Op.notBetween]: [new Date(), new Date(new Date() - 24 * 60 * 60 * 1000)]
}
});
我还建议使用moment.js或luxon(个人最喜欢的)来处理日期。 使用luxon格式化日期:
const DateTime = require('luxon');
// the reason we love luxon is because it's easy to set the timezone
const startDate = DateTime.local().setZone('America/New_York').fromISO('2020-04-24T11:00:00').toJSDate();
2条答案
按热度按时间v9tzhpje1#
Sequelize使用js date。所以你可以这样做:
我还建议使用moment.js或luxon(个人最喜欢的)来处理日期。
使用luxon格式化日期:
阅读更多:https://sequelize.org/master/manual/model-querying-basics.html
bfnvny8b2#
const currentDate = new Date().toISOString().slice(0,10);//获取ISO格式的当前日期try { const competitions = await CompetitionTable.findAll();