簡體   English   中英

我們如何才能僅從 Flutter 中的 Firestore 檢索前一天的數據?

[英]how we can retrieve only previous one day data from Firestore in Flutter?

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

我可以在此代碼中進行哪些更改以僅從 firebase firestore flutter 獲取前一天的數據?

我通過這個試過了

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(),

您可以使用以下格式獲取前一天,但您必須在數據將數據插入 firestore 時添加時間戳

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

如果你只想要 yest 數據:

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

另一個是如果你想在甲酸范圍內的數據

                await FirebaseFirestore
                          .instance
                          .collection('Orders')
                          .where('timestamp', isGreaterThanOrEqualTo: yd)
                          .where('timestamp', isLessThanOrEqualTo: td)
                          .get();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM