Skip to content
Back

[SOLVED] How to query documents using a date field, having in consideration timezones?

  • 0
  • Databases
  • Flutter
Isai
15 Feb, 2023, 15:55

Lets say I save a document at 05:00 am GTM-6 on feb 01, it will be saved in the database in UTC as 23:00 of January 21, If I query my documents of Feb 01, that specific document wont appear, is there a way to handle this?

TL;DR
Solution: To query documents using a date field while considering timezones, you can use the `listDocuments()` function and include both greater and less queries that are AND-ed together. You'll need to calculate the beginning and end of the timezone's day. Make sure to create the proper index for it. For example, if you save a document at 05:00 am GMT-6 on Feb 01, it will be saved in UTC as 23:00 of January 31. If you query for documents on Feb 01, that specific document won't appear. To handle this, you can do a between query using `
Tanner Meade
15 Feb, 2023, 16:11

I'd guess the best way is to do a between query. Query.greater() AND Query.less()

Tanner Meade
15 Feb, 2023, 16:12

You'll need to make the proper index for it, but that should do the trick. You just need to calculate the beginning and end of the timezone's day.

Tanner Meade
15 Feb, 2023, 16:14

When you query using listDocuments() the query parameter is a list of queries that are AND-ed together, so you just need both those greater and less queries in there.

Isai
15 Feb, 2023, 16:20

Thank you very much tanner 😄

VincentGe
15 Feb, 2023, 23:31

Do you mind marking this [SOLVED] in the title?

Isai
15 Feb, 2023, 23:32

[solved How to query documents using a date field, having in consideration timezones?

VincentGe
20 Feb, 2023, 19:46

[SOLVED] How to query documents using a date field, having in consideration timezones?

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