Tanvir
Tanvir

Reputation: 151

How to compare date in template Angular 4

How to compare array object date value from today ? I searched and tried in many ways but did not find a solution yet.

I have done so far as bellow:

*ngIf="patientPrescriptions.appointments_patient_updated_at > now"

Upvotes: 4

Views: 8187

Answers (2)

Tanvir
Tanvir

Reputation: 151

So I have solved it like this:

In typescript:

ngOnInit() {
  this.now = this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:s');
}

Upvotes: 2

Shekhar Patel
Shekhar Patel

Reputation: 671

I found this solution and it works for me, In your ts file

const now = new Date;
today: string ;
this.today =now.toISOString();

And in your html file,

 *ngIf= "model.LeaveFrom > today"

It gives you date if model date is greater than today.

Upvotes: 2

Related Questions