Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare date in template Angular 4

Tags:

angular

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"
like image 649
Tanvir Avatar asked Oct 22 '25 00:10

Tanvir


2 Answers

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.

like image 72
Shekhar Patel Avatar answered Oct 23 '25 14:10

Shekhar Patel


So I have solved it like this:

In typescript:

ngOnInit() {
  this.now = this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:s');
}
like image 26
Tanvir Avatar answered Oct 23 '25 13:10

Tanvir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!