Lim
Lim

Reputation: 31

timestamp range query firebase flutter

The following image is my firebase document, how do i retrieve documents based on date range, is it possible ? So far i have tried this method but it does not work, any idea how ?

allNoteCollection = FirebaseFirestore.instance.collection('Appointment')
  ..where('filter', isGreaterThanOrEqualTo: '6 December 2022 at 08:00:00 UTC+8')
  .where('filter', isLessThanOrEqualTo: '30 December 2022 at 08:00:00 UTC+8');

enter image description here

Upvotes: 0

Views: 594

Answers (1)

Camillo bucciarelli
Camillo bucciarelli

Reputation: 352

You have to use something like this:

FirebaseFirestore.instance.collection('Appointment')
    .where('filter', isGreaterThanOrEqualTo: Timestamp.fromDate(DateTime(2022, 12, 6)))
    .where('filter', isLessThanOrEqualTo: Timestamp.fromDate(DateTime(2022, 12, 30)));

Remember to create a proper index on firestore.

Upvotes: 2

Related Questions