【问题标题】:How to compare two dates in Sequelize?如何在 Sequelize 中比较两个日期?
【发布时间】:2021-08-17 22:31:30
【问题描述】:

我在使用模型查询时遇到问题。

如果我想比较两个日期,例如,一个在数据库中找到,另一个是今天的日期。

我是这样写的。

model.findAll({
where:{
  startDate:{
      [Op.gt]:now Date().toISOString(),
}
}
})

is this a good way to compare??


【问题讨论】:

标签: javascript node.js database sequelize.js


【解决方案1】:

试试这个方法:

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
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-13
    • 2011-04-20
    • 1970-01-01
    • 2022-01-05
    • 2016-06-25
    相关资源
    最近更新 更多