0

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!

QWERTY
  • 2,303
  • 9
  • 44
  • 85

1 Answers1

0

It seems you're using Moment.js. So you can do:

this.staff.staffDob.isSameOrAfter(new Date())

More details: https://momentjs.com/docs/#/query/is-same-or-after/

AskYous
  • 4,332
  • 9
  • 46
  • 82