Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get day difference between current date with dates stored in firebase firebase and display the result in an html table

I am retrieving a firebase collection using JavaScriptjaca and intend to get the difference between the current date and dates stored in the returned collection.

 this.firebaseSrvc.function().subscribe((data)=>{
             data.forEach(e =>{ 
    const x = new Date(e.dataPagamento).toLocaleDateString();
    const y = new Date().toLocaleDateString();
    const a = Math.abs(new Date(y).valueOf() - new Date(x).valueOf());
    const b = Math.ceil(a/(1000*60*60*24));
    this.dates = b;
});
});

After that I want to populate an html table with "this.dates", but only appears the last item

<ion-grid>
    <ion-row>
      <ion-col id="b">{{dates}}</ion-col>
    </ion-row>
 </ion-grid>

I need help on how to fill the table with all this.dates values

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Store the result in an array, not in a single number.

Try this:


this.firebaseSrvc.function().subscribe(
  (data)=>{
    this.dates = []; // <---- Create an empty array
    data.forEach(e =>{ 
      const x = new Date(e.dataPagamento).toLocaleDateString();
      const y = new Date().toLocaleDateString();
      const a = Math.abs(new Date(y).valueOf() - new Date(x).valueOf());
      const b = Math.ceil(a/(1000*60*60*24));
      this.dates.push(b);  // <---- Push each result as a new entry in the array
  });
});

Display the array using a for loop

For example, if you are using Ionic Vue:

<ion-grid>
    <ion-row>
      <ion-col  v-for="date in dates">{{date}}</ion-col>
    </ion-row>
 </ion-grid>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading