Back

[SOLVED] Use Query.between() to list documents by date

  • 0
  • Flutter
  • Functions
Mingu
2 Jan, 2025, 11:26

Hello, I want to get a list of Document by Query.between using date.

TypeScript
    String today = DateTime.now().toString().substring(0, 10); // YYYY-MM-DD
    String oneMonthAgo = DateTime.now().subtract(Duration(days: 30)).toString().substring(0, 10);
...
  dataMonth = database.listDocuments(
        databaseId: databaseId,
        collectionId: collectionId,
        queries: [
          Query.between(
              '\$createdAt',
              oneMonthAgo,
              today),
        ]
...
  context.log("Documents");
      dataMonth.documents.every(
        (element) {
          context.log(element.data['data']);
          return true;
        },
      ); 
// Printed 1 document, expected 3 documents

There are 3 documents with the same CreatedAt date, but only one of them is returned. Is there anything I did wrong?

TL;DR
Title: [SOLVED] Use Query.between() to list documents by date Devs had a timezone issue causing improper date calculation. Solution: Add a whole day to DateTime today like so: ``` String today = DateTime.now().add(Duration(days: 1)).toString().substring(0, 10); String oneMonthAgo = DateTime.now().subtract(Duration(days: 31)).toString().substring(0, 10); ```
Mingu
2 Jan, 2025, 11:47

Reason: different timezone, about 6 hours before the server fix: add a whole day to DateTime today

TypeScript
    String today = DateTime.now().add(Duration(days: 1)).toString().substring(0, 10);
    String oneMonthAgo = DateTime.now().subtract(Duration(days: 31)).toString().substring(0, 10);
Mingu
2 Jan, 2025, 11:48

[SOLVED] Use Query.between() to list documents by date

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more