1

I try to compare date from MySQL:DATENOW and compare it with date now in angular.

This is my function

  getReports(onSuccessCallback: Function) {
    this.http.getReports(Globals.userID).subscribe(data => {
      data.map((report) => {
        const nowDay = new Date().toLocaleDateString();
        report.deadLine = new Date(report.deadLine).toLocaleDateString();
        if (report.deadLine === nowDay) {
          console.log(true);
        }
      });
      onSuccessCallback(data);
    }, error => {
      console.log(error);
    });
  }
}

When i do this is work fine and take whats equal and console true, but the problem is whan i try to console true if Date already passed I try:

if (report.deadLine < nowDay){
          console.log(true);
        }

and its not work

Baruch_Mashasha
  • 197
  • 1
  • 3
  • 13

1 Answers1

0

You have To Change The Code Set

  const nowDay = new Date().toLocaleDateString();
            report.deadLine = new Date(report.deadLine).toLocaleDateString();
           if (report.deadLine < nowDay){
          console.log(true);
        }

To This

 const nowDay = new Date();
        report.deadLine = new Date(report.deadLine);
        if (report.deadLine < nowDay){
          console.log(true);
        }
DeC
  • 2,226
  • 22
  • 42