compare two dates in Angular 6

you can use getTime

if (input1Date.getTime() < input2Date.getTime()) 

Note that if your dates are in string format, you first need to parse them to Date


Angular has builtin formatDate method so you can use it to format your date and also compare it simply like below code:

In your component.ts file:

   date1 = formatDate(new Date(),'yyyy-MM-dd','en_US');
   date2 = let FToday = formatDate(datecomingfromdb,'yyyy-MM-dd','en_US');

   if(date1>date2){
     console.log('---date1 is greater----');
    }else{
     console.log('---date2 is greater-----');
    }

hope this helps and you can read more in Angular docs here


finally I found the solution.

console.log(mMagazineObject.From < this.datePipe.transform(mMagazineObject.To, 'yyyy-MM-dd') ? true : false);