I have a date in string format in firebase collection, and I am trying to display it. As far as I understand, pipe filters doesn't work for strings, and only for Date objects. To do this, I need to use custom pipe.
I used the below function:
transform(value: string) {
var datePipe = new DatePipe("en-US");
value = datePipe.transform(value, 'MM-dd-yyyy');
return value;
}
and one with moment:
transform(value: string) {
let d = new Date (value);
return moment(d).format('DD-MM-YYYY');
}
The first one is giving below error:
and the second is giving invalid date.
Below is the data in the collection:
Below is the pipe file:
import {Pipe, PipeTransform} from '@angular/core';
import { DatePipe } from '@angular/common';
import * as moment from 'moment'
@Pipe({
name: 'dateFormatPipe'
})
export class formatDate implements PipeTransform {
transform(value: string) {
var datePipe = new DatePipe("en-US");
value = datePipe.transform(value, 'MM-dd-yyyy');
return value;
}
}
And below is the html:
<tr *ngFor="let v of list">
<td>{{v?.NoOfDays}}</td>
<td>{{v?.vacationType|json}}</td>
<td>{{v?.SubmissionDate.toDate()|date}}</td>
<td>{{v?.fromDate| dateFormatPipe }}</td>
<td>{{v?.endDate | dateFormatPipe }}</td>
</tr>
P.S. SubmissionDate is working fine, as it is a date object, while, fromDate, and endDate are not working.
Any suggestions?
Thanks in advance

