monir tuhin
monir tuhin

Reputation: 541

How to convert date time in to required date format in angular date pipe?

I am using angular 8. I want to convert this date time format ("17/06/2020 10:01:09") in to this format ("17/06/2020"). But i can't resolve this issue. I am getting this error "InvalidPipeArgument: 'Unable to convert "17/06/2020 10:01:09" into a date' for pipe 'DatePipe'".

//html

<p>My date: {{myDate | date:'dd/MM/yyyy'}}</p>

//ts file

import { Component } from '@angular/core';

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html'
})
export class AppComponent {
   myDate = '17/06/2020 10:01:09';
}

Please help to find me a solution. thanks.

Upvotes: 0

Views: 3498

Answers (1)

behruz
behruz

Reputation: 598

angular Date pipe works on Date object not on a string;

myDate = new Date();

and then your pipe works fine;

Upvotes: 1

Related Questions