繁体   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