我正在从数据库中提取一个名为 expiry_date 的时间戳,我需要检查该时间是否距当前日期不到一个月。
db.collection('inventory/clubs/MUCK').where("expiry_date", "<=", Date.now()-2592000000) //check the database for every date less than a month from the present.
.get()
.then(function(querySnapshot){
var count = 0;
querySnapshot.forEach(function(doc){
count++; //increment for every hit.
});
console.log(count);
});
这是我到目前为止的尝试,它只是记录了 0 的计数,但集合中的某些项目距离现在还不到一个月。
最佳答案
使用 Firestore,您无法像现在一样将时间戳类型字段与整数值进行比较。您需要为查询构建 Firestore Timestamp 或 JavaScript Date 对象。
where("expiry_date", "<=", new Date(Date.now() - some_delta))
关于javascript - 我想将时间戳与当前时间减去一个月进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314827/