InvalidPipeArgument: '18.06.2009' for pipe 'DatePipe'?

3.5k Views Asked by At

I have this in .ts file :

 this.newDate = '18.06.2009';

In my html i have this:

  <h5 class="datetime">{{ newDate | date: 'dd MMMM yyyy'}}</h5>

Any suggestion what is wrong with this? How can i fix that so that i get:

1 June 2009
2

There are 2 best solutions below

1
On

The date pipe expects a timestamp(number) or a Date instance and you're sending a string as input. You can create the date object with something like:

this.newDate = new Date('06.01.2009')

and then it will work correctly. Have a look at the docs for more info on how to work with dates.

0
On

You have set the date incorrectly , like a string it should be a date instance and also the pipe argument should be 'dd MMM yyyy' instead of 'dd MMMM yyyy'

newDate = new Date();

{{ newDate | date: 'dd MMM yyyy'}} // MMM instead of MMMM