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?
What is the value of the date being used in the query?
2023-12-15T00:00:00.000
Did you use .toUtc() in the query?
GitHub issue for reference: https://github.com/appwrite/appwrite/issues/7290
Query.equal('date', date.toUtc().toIso8601String()),
result as before, nothing with this query
Would you please share the JSON data for the document? as well as how you're getting the date for the query?
{..., 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
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
and you're on Appwrite Cloud and the attribute is a datetime attribute?
Yes
any chance i can test against your collection?
yea sure
Is the collection public? I'll also need the project id, database id, and collection id
Yes, ill send to you
and what's your output of:
print(Query.equal('date', date.toUtc().toIso8601String()));
equal("date", ["2023-12-13T23:00:00.000Z"])
is that the right day?
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"])
Ill send to you in private the data?
ya sure
Ok sent
So what's you're updated code now?
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.
Recommended threads
- Error With iOS Apps
I keep getting the below errors for my flutter app. The clients are registered and have been. This wasn't an issue a few hours ago. AppwriteException: AppwriteE...
- Appwrite Auth & Function don't reveal cl...
When I execute a function or sign in with my Flutter app, Appwrite does not show my real IP: instead, it seems that Appwrite shows Fastly CDN IP address.
- Why does this happen?
`AppwriteException: general_argument_invalid, Invalid `secret` param: Value must be a valid string and at least 1 chars and no longer than 256 chars (400)` the...