I'm looking to work with timestamp queries.
Note: setSD and setED are part of the Vue object's data, and the firebase function call is within the method.
callFirebase: function (){
let startdate = new Date(this.setSD+'T00:00:00');
let enddate = new Date(this.setED+'T00:00:00');
console.log(startdate);
console.log(enddate);
db.collection("study").
where("time", ">=", firebase.firestore.Timestamp.fromDate(startdate)).
where("time", "<=", firebase.firestore.Timestamp.fromDate(enddate))
.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data().time.toDate());
});
})
.catch(function (error) {
console.log("Error getting documents: ", error);
});
}
}
Error illustration:
https://i.sstatic.net/FX1Oo.png
callFirebase: function (){
let startdate = new Date(this.setSD+'T00:00:00');
let enddate = new Date(this.setED+'T00:00:00');
console.log(startdate);
console.log(enddate);
db.collection("study").
where("time", ">=", new Date(this.setSD+'T00:00:00')).
where("time", "<=", new Date(this.setED+'T00:00:00'))
.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data().time.toDate());
});
})
.catch(function (error) {
console.log("Error getting documents: ", error);
});
}
}
However, my attempts have led to the same issue.
callFirebase: function (){
let startdate = new Date(this.setSD+'T00:00:00');
let enddate = new Date(this.setED+'T00:00:00');
console.log(startdate);
console.log(enddate);
db.collection("study").
where("time", ">=", new Date('2019-12-31T00:00:00')).
where("time", "<=", new Date('2020-01-01T00:00:00'))
.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data().time.toDate());
});
})
.catch(function (error) {
console.log("Error getting documents: ", error);
});
}
}
My main confusion lies in why this particular setup works. I initially assumed that I couldn't use variables in the where clause. However, after further investigation, it seems that might not be the case. Can someone provide some assistance?