Fetching datetime from firebase database and showing them in ionic datetimepicker


Hello guys!
I have a firebase database:

I am trying to fetch all the date from this database so the user can only select those dates (without HHMMSS, just the YYYYMMDD) available in the db from the datetimepicker. The reason i need this because i will use the datetimepicker as a page filter showing only datas for the selected date.

<ion-item *ngFor="let item of fogasadatok; let i = index">
        <ion-label>Start Time</ion-label>
        <ion-datetime displayFormat="YYYY-MM-DD" pickerFormat="YYYY-MM-DD" [(ngModel)]="event.timeStarts"></ion-datetime>

I have no idea how to continue this code, can you show me the way?


You could try to format the data you get from Firebase using MomentJS into the right format for your datepicker:

let foo = moment(event.timeStarts, "YYYY-MM-DD");

Then you need to set this data as the ngModel of your picker!


Thank you.

I created this in the ts:

ngOnInit() {
    let magyardatum = moment().format('LL');

But what should i write to the ngmodel now?


@saimon Just FYI: the conventional wisdom on the board right now is that date-fns is better for Ionic apps than momentJS. I agree with this - more lightweight, better tree shaking. The only area Moment is better is in definition of complex and conditional time zones. This could change tomorrow with new updates etc., but for now, you might benefit from exploring date-fns.