skip to Main Content
FirebaseFirestore.instance
.collection("Orders")
.where('ostatus', isEqualTo: "4")
.where('vid', isEqualTo: uid)
.orderBy("latestorder", descending: true)
.snapshots(),

Which change can i do in this code to get only previous one day data from firebase firestore flutter?

2

Answers


  1. Chosen as BEST ANSWER

    I tried it through this

    FirebaseFirestore.instance
                .collection("Orders")
                .where('ostatus', isEqualTo: "4")
                .where('vid', isEqualTo: uid)
                .where("latestorder",
                    isGreaterThanOrEqualTo:
                        Timestamp.now().toDate().subtract(Duration(days: 1)))
                .orderBy("latestorder", descending: true)
                .snapshots(),
    

  2. you can use the below format to get a previous day, but you have to add a timestamp while the data is inserting data into firestore

      DateTime todaysDate = DateTime.now();
      DateTime yd = DateTime.utc(todaysDate.year, todaysDate.month, todaysDate.day -1);
    

    If you want to only yest data :

                      await FirebaseFirestore
                                  .instance
                                  .collection('Orders')
                                  .where('ostatus', isEqualTo: "4")
                                  .where('timestamp', isEqualTo: yd)
                                  .get();
    

    Another is if you want to data in range formate

                    await FirebaseFirestore
                              .instance
                              .collection('Orders')
                              .where('timestamp', isGreaterThanOrEqualTo: yd)
                              .where('timestamp', isLessThanOrEqualTo: td)
                              .get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search