I was having some problem when trying to compare dates in Angular typescript. Here is my code:
let todayDate = new Date();
if ((Date.parse(this.staff.staffDOB.format(DATE_FORMAT))) >= (Date.parse(this.datePipe.transform(todayDate, DATE_FORMAT)))){
this.isValidDob = false;
}
The example of staffDOB is in this format '2019-03-07'
. Then I kept getting true
returned regardless of changing the compare operator to <=
or >=
.
I not sure which part went wrong. Any ideas? Thanks!