我在使用模型查询时遇到问题。
例如,如果我想比较两个日期,一个在数据库中找到,另一个是今天的日期。
我是这样写的。
model.findAll({
where:{
startDate:{
[Op.gt]:now Date().toISOString(),
}
}
})
is this a good way to compare??
最佳答案
试试这个方法:
const { Op } = require('sequelize'); // "npm i sequelize"
const moment = require('moment'); // "npm i moment"
model.findAll({
where: {
startDate: {
// $gt: moment().toDate(), // Sequelize version < 5
[Op.gt]: moment().toDate(), // Sequelize version 5
}
}
});
关于javascript - 如何比较Sequelize中的两个日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67759820/