I'm trying to parse a date with this format dd/mm/yyyy to yyyy-mm-dd with typescript in order to send the correct format to an API request. I'm using this function before sending the request:
formatDateForBE(date: string): string {
if (date) {
return this.datePipe.transform(date,'yyyy-MM-dd' )
}
return null;
}
and I get this error:
Can someone explain why and help me solve it? I'm using basically the same method to transform and show the dates that I get from the API (yyyy-mm-dd TO dd/mm/yyyy) and it works. Why is this one not working?
Thanks!