Back

Unable to query an appwrite collection by date with flutter

  • 0
  • Flutter
Carlo
15 Dec, 2023, 21:45

I need to query a collection by using a date query but i'm not able to find a solution.

I posted on stack the question https://stackoverflow.com/questions/77665907/appwrite-unable-to-query-by-date-with-dart/77667807#77667807 but i hope to find a solution here.

Basically i'm query the db like that: final response = await _db.listDocuments( databaseId: AppwriteConstants.database_id, collectionId: AppwriteConstants.collection_id_events, queries: [ Query.equal('fk_user', fk_user), Query.equal('​​date', date.toIso8601String()), ], );

and the documents are created like that:

final response = _db.createDocument( databaseId: AppwriteConstants.database_id, collectionId: AppwriteConstants.collection_id_events, documentId: .., data: { ... 'date': date.toIso8601String(), 'startTime': startTime.toIso8601String(), 'endTime': endTime.toIso8601String(), ... }, ); In the collection the date are added with the time setted to 0, like 2023-12-15T00:00:00.000 but once i recover the documents without the date query i obtain the date in this format 2023-12-15T00:00:00.000+00:00. If i use the query like in the example nothing is returned.

I tried to insert in appwrite the date like date.toUct().toIso8601String() but nothing changed. Some help?

TL;DR
The user is unable to query an Appwrite collection by date using Flutter. The user has tried querying the database using the `listDocuments` method with a date query, but it is not returning any results. The user has also tried adjusting the date format and using the `toUtc()` and `toIso8601String()` methods without success. The user has posted a question on Stack Overflow and is hoping for a solution. Solution: It is suggested to check the format of the date being used in the query and ensure that the date is being properly formatted and matched with the documents in the collection. It is also recommended to refer
Ryan
15 Dec, 2023, 21:52

What is the value of the date being used in the query?

Carlo
15 Dec, 2023, 21:56

2023-12-15T00:00:00.000

Drake
15 Dec, 2023, 21:56

Did you use .toUtc() in the query?

Drake
15 Dec, 2023, 21:57
Carlo
15 Dec, 2023, 21:58

Query.equal('​​date', date.toUtc().toIso8601String()),

Carlo
15 Dec, 2023, 21:58

result as before, nothing with this query

Drake
15 Dec, 2023, 21:59

Would you please share the JSON data for the document? as well as how you're getting the date for the query?

Carlo
15 Dec, 2023, 21:59

{..., date: 2023-12-14T23:00:00.000+00:00, ... } without the query. With the query the date parameter with utc and iso8601string is 2023-12-14T23:00:00.000Z

Carlo
15 Dec, 2023, 22:02

As you can se in the JSON data i putted the date in format with uct and iso8601String as suggested in the issue on github. Since the date before this adjustment was without the 23:00:00 time but only 00:00:00

Drake
15 Dec, 2023, 22:03

and you're on Appwrite Cloud and the attribute is a datetime attribute?

Carlo
15 Dec, 2023, 22:03

Yes

Drake
15 Dec, 2023, 22:03

any chance i can test against your collection?

Carlo
15 Dec, 2023, 22:03

yea sure

Drake
15 Dec, 2023, 22:04

Is the collection public? I'll also need the project id, database id, and collection id

Carlo
15 Dec, 2023, 22:06

Yes, ill send to you

Drake
15 Dec, 2023, 22:06

and what's your output of:

TypeScript
print(Query.equal('​​date', date.toUtc().toIso8601String()));
Carlo
15 Dec, 2023, 22:07

equal("​​date", ["2023-12-13T23:00:00.000Z"])

Drake
15 Dec, 2023, 22:07

is that the right day?

Carlo
15 Dec, 2023, 22:09

Yes, sorry for the example but it is a dynamic calendar so once i change page to another date i call a query with the visualized date. Is the same for the 14 for which i get no data back: equal("​​date", ["2023-12-14T23:00:00.000Z"])

Carlo
15 Dec, 2023, 22:09

Ill send to you in private the data?

Drake
15 Dec, 2023, 22:09

ya sure

Carlo
15 Dec, 2023, 22:13

Ok sent

Drake
15 Dec, 2023, 22:27

So what's you're updated code now?

Carlo
15 Dec, 2023, 22:39

final response = await _db.listDocuments( databaseId: AppwriteConstants.database_id, collectionId: AppwriteConstants.collection_id_events, queries: [ Query.equal('fk_user', fk_user), Query.equal('date', date.toUtc().toIso8601String()), ], );

Idk maybe flutter was bugged but this is working fine now.

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