Javascript Sequelize-如何比较日期之间的相等性
如何比较两个日期之间的相等性? 似乎以下方法不起作用:Javascript Sequelize-如何比较日期之间的相等性,javascript,node.js,typescript,orm,sequelize.js,Javascript,Node.js,Typescript,Orm,Sequelize.js,如何比较两个日期之间的相等性? 似乎以下方法不起作用: const result: SomeModel= SomeModel.findOne( {where: { startTime : { [Op.eq] : someDateTime } } }); 请试一试 const result: SomeModel= SomeM
const result: SomeModel= SomeModel.findOne( {where:
{
startTime : {
[Op.eq] : someDateTime
}
}
});
请试一试
const result: SomeModel= SomeModel.findOne( {where:
{
startTime : {
[Op.and] : someDateTime
}
}
});
以下是可以执行的所有操作的列表
Project.findAll({
where: {
id: {
[Op.and]: {a: 5}, // AND (a = 5)
[Op.or]: [{a: 5}, {a: 6}], // (a = 5 OR a = 6)
[Op.gt]: 6, // id > 6
[Op.gte]: 6, // id >= 6
[Op.lt]: 10, // id < 10
[Op.lte]: 10, // id <= 10
[Op.ne]: 20, // id != 20
[Op.between]: [6, 10], // BETWEEN 6 AND 10
[Op.notBetween]: [11, 15], // NOT BETWEEN 11 AND 15
[Op.in]: [1, 2], // IN [1, 2]
[Op.notIn]: [1, 2], // NOT IN [1, 2]
[Op.like]: '%hat', // LIKE '%hat'
[Op.notLike]: '%hat', // NOT LIKE '%hat'
[Op.iLike]: '%hat', // ILIKE '%hat' (case insensitive) (PG only)
[Op.notILike]: '%hat', // NOT ILIKE '%hat' (PG only)
[Op.overlap]: [1, 2], // && [1, 2] (PG array overlap operator)
[Op.contains]: [1, 2], // @> [1, 2] (PG array contains operator)
[Op.contained]: [1, 2], // <@ [1, 2] (PG array contained by operator)
[Op.any]: [2,3] // ANY ARRAY[2, 3]::INTEGER (PG only)
},
status: {
[Op.not]: false // status NOT FALSE
}
}
})
Project.findAll({
其中:{
身份证:{
[Op.and]:{a:5}、//和(a=5)
[Op.or]:[{a:5},{a:6}],//(a=5或a=6)
[Op.gt]:6,//id>6
[Op.gte]:6,//id>=6
[Op.lt]:10,//id<10
[Op.lte]:10,//id[1,2](PG阵列包含运营商)
[执行部分]:[1、2],//它取决于startTime和someDateTime的类型。添加模型定义和此列的DB类型,以及someDateTime中的值。还要指出您使用的wgat DBMS startTime是类型Date。someDateTime是日期对象。我使用PostgresQL进行生产。用于单元测试SQLite。相等比较的两侧都包含时间p艺术这就是它们不相等的原因。请尝试使用以下内容:Sequelize.where(Sequelize.fn('date',Sequelize.col('startTime')),Sequelize.fn('date',someDateTime))(请记住,sqlite可能不支持此函数)这也会比较日期变量的时间部分吗?我想比较日期和时间。两者都应该相等。在这种情况下,您应该检查并比较DB和变量中的时区。它们相等吗?PostreSQL DB中列的确切类型是什么?有时区还是没有时区?