So i have my records in firebase cloud firestore like this :
[
{
"category":"drinks",
"expensetype":"card",
"id":"5c673c4d-0a7f-9bb4-75e6-e71c47aa8d1d",
"name":"JJ",
"note":"YY",
"price":57,
"timestamp":"2017-11-30T22:44:43+05:30"
},
{
"category":"drinks",
"expensetype":"card",
"id":"85731878-eaed-2740-6802-e35e7758270b",
"name":"VV",
"note":"TTT",
"price":40,
"timestamp":"2017-12-30T22:41:13+05:30"
}
]
I want to query data with the timestamp and get data that belongs to a particular month or date.
For example if I click a particular month (say March) in my calendar, I want only the data of that particular month in my results. How can i do that?
I have saved the date using
firebase.firestore.FieldValue.serverTimestamp()
Thanks in advance for any help.
Edit :
This is how I form my query
var spendsRef = this.db.collection('spend', ref => ref.where("timestamp", ">", "12-12-2017"));
this.items = spendsRef.valueChanges();
But it still returns me all the data in Database
Answer :
var todayDate = new Date("Tue Jan 02 2018 00:00:00 GMT+0530 (IST)") // Any date in string
var spendsRef = this.db.collection('spend', ref => ref.where("timestamp", ">", todayDate));
this.items = spendsRef.valueChanges();
Using two relative operators, you can determine the precise range of documents returned by the query:
ref.where("timestamp", ">=", "2017-11").where("timestamp", "<", "2017-12")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With