Manipulate Value Stored In Firebase Document Field Before Applying Order By
In my Firebase Firestore, I have a large number of documents in a collection, each of which has a field called bookTime, which stores a date in String format. The format is dd MM y
Solution 1:
What change should I make so I can actually get a list with the document having newest bookTime on top?
First of all, don't use Strings to store dates. It's recommended to use Date objects. The Date
is a Firestore supported data type.
For more information on how to store a Date, please see my answer from the following post:
Once you store the Date correctly, that query will work perfectly fine.
However, if you insist to store the dates and times as Strings, the option that you have is to store them in a format that can be sorted lexicographical and chronological at the same time.
The ISO 8601 format looks like this:
20200329T184525
That's the current time I'm answering this question.
March29,2020 6:45:25 PMUTC
Post a Comment for "Manipulate Value Stored In Firebase Document Field Before Applying Order By"