I am trying to compare dates in my app using ngIf, but I haven't been able to get it working properly so far.
<div *ngIf="(todaysdate | date:'MMM dd' == duedate | date:'MMM dd')">
List
</div>
I want to compare them using the date pipe because times on the full date string are different I only want to compare the dates. Any suggestions on how to properly do this are much appreciated.
Compare works fine when you format your dates properly (eg. 20191224 for christmas). So this should work
<div *ngIf="(todaysdate | date:'yMMdd' == duedate | date:'yMMdd')">
List
</div>
The quickest solution is to this.todaysdate.setHours(0, 0, 0, 0);
which you would do on your date prior in your constructor.
But you can also send it to and expression on the component *ngIf="compareDates()"
compareDates(){
return this.todaysdate.setHours(0, 0, 0, 0) == this.duedate.setHours(0, 0, 0, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With