Sort data by date in Firebase

Asked

Viewed 913 times

0

I would like to sort the data returned from Firebase by Due Date, at the moment I am doing as follows:

this.Collection = document.collection('values', ref => ref.orderBy('data_vencimento'));

But how can it be seen in the image below, is not ordering correctly, there are other ways to sort by date? I can do a Sort() on the Observable returned from Firebase?

inserir a descrição da imagem aqui

  • 1

    Actually it is ordering correctly, but it will not have the desired result because it is ordering like a string not like a date in the BR format, if you change to the format for yyyy-mm-dd, will have the desired result

  • Okay, I’ll check it out...

  • On the bench needs to be saved in YYY-MM-DD format for orderby to work properly, thank you!

2 answers

1

Guy the idea would be to save, date on timestamp in a new property for example:

const data = new Date();

const meuObjeto = {
    data: data.toLocaleDateString(),
    timestamp: data.getTime()
};

So you can compare both time differences and sort etc...

0

Actually it is ordering correctly, but it will not have the desired result because it is ordering like a string not like a date in the BR format, if you change the format to yyyy-mm-dd, will have the desired result.

I suggest that I use the American standard in the bank and make a mask of the dates in the front-end, for example:

var data = new Data //Retorna no formato Tue Mar 13 2018 15:23:51 GMT-0300 (-03)
data.toLocaleDateString() //Retorna no formato 13/03/2018

Browser other questions tagged

You are not signed in. Login or sign up in order to post.