firebase - 是否可以根据 dateTime 值从 firebase 查询文档到颤动?
问题描述
我试图以两种方式从我的firestore查询文档到我的flutter应用程序,第一种是当我的“Patients”集合中的“translator”字段为='$ currentUser'时获取所有文档,如下所示并且工作正常:
FirebaseFirestore.instance
.collection('Patients')
.where('translator', isEqualTo: _auth.currentUser!.displayName)
.snapshots()
接下来我要做的是根据“到达日期”字段查询数据,该字段是 DateTime 格式化为字符串,如图所示
我怎样才能得到当前日期时间在到达日期之前的所有文件,像这样
FirebaseFirestore.instance
.collection('Patients')
.where('arrivalDate' , '????': arrivalDate.isBefore(DateTime.now())
解决方案
当然,您只需要将日期格式设置为与文档中相同的格式。
像这样的东西:
import 'package:intl/intl.dart';
...
String formattedDate = DateFormat('yyyy-MM-dd').format(now);
FirebaseFirestore.instance
.collection('Patients')
.where('arrivalDate' , isLessThan: formattedDate)
推荐阅读
- python - 如何检查单元格是否在 Pandas 中具有特定字符
- python - 错误提示而不是提示重新输入输入
- javascript - Youtrack Workflow 无缘无故地为 http 库抛出异常
- java - Maven 在运行“测试”和“安装”时执行测试的方式不同吗?
- oop - 开闭原则是否意味着我们必须将每个方法都定义为虚拟的?
- graphics - 如何计算像素在形状范围内的百分比
- python - 如果服务器不允许 SSH 连接,扭曲的 SFTP 客户端可以工作吗?
- python - 是否可以在没有 tbody 标签的情况下在 google 或 chrome 中复制 xpath?
- javascript - 在 Javascript 中将数组设置为 Map 值
- python - 如何用 Beautifulsoup 刮一张隐藏的桌子