Sort by date does not work - Firestore
Hello, I have a variable in the database that contains the date in format "dd/MM/yyyy", when I try to use the orderby of a query with that date firebase uses only the days (dd) to sort my recyclerView, causing the query not to be ordered efficiently, how can I get around this problem? There is no way to remove the " / " after they are in the database as the method .orderBy requires as a parameter a field value that is in the database (existing there (22/04/1947)) and not a local value, I saw that it is possible to use TimeStamp, but if I use timeStamp, I would show pro my user "144546541", which is nothing readable...
Example of sorting: anuncioRef.orderBy(campo, Query.Direction.ASCENDING).limit(100);
, where field is a value stored in the database and that is not changed here, field here is the date value (dd/MM/yyyy)
1 answers
After getting the database date, I formatted it following this tutorial
And the code looked like this in my RecyclerView:
String data = anuncioPrincipal.getDataAnuncio();
SimpleDateFormat formInicio = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat formFim = new SimpleDateFormat("dd/MM/yyyy");
try {
data = formFim.format(formInicio.parse(data));
} catch (ParseException e) {
e.printStackTrace();
}