FirebaseFirestore.instance .collection("Orders") .where('ostatus', isEqualTo: "4") .where('vid', isEqualTo: uid) .orderBy("latestorder", descending: true) .snapshots(),
我可以在这段代码中做什么改变来从firebase firestore flutter中只获取前一天的数据?
xdnvmnnf1#
我试过了
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(),
slhcrj9b2#
你可以使用下面的格式来获取前一天,但是你必须在数据插入到firestore时添加时间戳
DateTime todaysDate = DateTime.now(); DateTime yd = DateTime.utc(todaysDate.year, todaysDate.month, todaysDate.day -1);
如果只想查看昨天的数据:
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();
2条答案
按热度按时间xdnvmnnf1#
我试过了
slhcrj9b2#
你可以使用下面的格式来获取前一天,但是你必须在数据插入到firestore时添加时间戳
如果只想查看昨天的数据:
另一种情况是如果你想把数据格式化