Why when I do this filter it returns all records from my database? What I need is that it returns only records within the range of the two dates.
async function toFind() { console.log("start", dateRangePicker.start); console.log("end", dateRangePicker.end); const importacao = db.collection("importacao"); await importacao .orderBy('data') .where("data", '>=', dateRangePicker.start) .where("data", '<=', dateRangePicker.end) .get() .then((snapshot) => { if (snapshot.empty) { toast.error('No matching documents.'); return; }
{ //database comentario: “teste”, custo:”3,000″, data:”18/08/2021″, dolar:”5.56″ }
Advertisement
Answer
You seem to be storing your dates as string values with the format “dd/MM/yyyy”. That is not a great format for storing dates, as strings are ordered lexicographically and in that order “18/08/2021” is before “19/09/2020”.
If you want to store dates, do so in an ISO-8601 format like “2021-08-18”. In that format the lexicographical order is the same as the chronological order, so you get the result you want.