1

i want to fetch the docs based on a date im inputing , and these docs have their timestamp in docs data , i tried querying with where() but still not working or maybe im not doing in the right way

im getting the date from this library



  const showDatePicker = () => {
    setDatePickerVisibility(true);
  };

  const hideDatePicker = () => {
    setDatePickerVisibility(false);
  };

  const handleConfirm = (date) => {
    setDate(date);
    hideDatePicker();
  };
 <Button title="Show Date Picker" onPress={showDatePicker} />
      <DateTimePickerModal
        isVisible={isDatePickerVisible}
        mode="date"
        onConfirm={handleConfirm}
        onCancel={hideDatePicker}
      />

And this is my query

  const finishedRef = collection(db, "validatedOrders");
     const finishedQ = query(
       finishedRef,
       where("status", "==", "Delivered"),
       where("date", "==")
     );
const finishedSnapshot = await getDocs(finishedQ);
     finishedSnapshot.forEach((doc) => {
       finished.push(doc.id);
     });


Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Zaki Kendil
  • 237
  • 2
  • 9
  • The code you shared defines a query `finishedQ`, but doesn't [read data](https://firebase.google.com/docs/firestore/query-data/get-data) from it as far as I can see. – Frank van Puffelen May 27 '22 at 21:07
  • i updated the post where i used the data , the problem is i want to get the docs with same date as the one i got from the date picker , but didnt know how – Zaki Kendil May 27 '22 at 21:51
  • That depends on what values the `date` fields in your database have. If they are `Timestamp` values, you'll need to use add both `>=` and `<` conditions on that field for the range of timestamps for the `date` values you want returns. – Frank van Puffelen May 27 '22 at 21:59

1 Answers1

1

If the date fields in your database have Timestamp values, you'll need to use add both >= and < conditions on that field for the range of timestamps for the date values you want returns.

See for an example of this: Firestore Cloud Function query by DATE and Firestore query by date range

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807