-1

I want to compare two dates. I'm new in Angular

The two dates are in same format mm/dd/yyyy

  <pre>{{CurrentDate | date:'MM/dd/yyyy' }}</pre>
  <pre>{{cmp_actl_del_date }}</pre>

these three are my dates. I want to check cmp_actl_del_date > the current date.

halfer
  • 19,824
  • 17
  • 99
  • 186
robins
  • 1,668
  • 6
  • 33
  • 69
  • Check out this: **http://stackoverflow.com/questions/37707377/how-to-compare-two-dates-in-angularjs** Hope it will help you. – The JD Nov 17 '16 at 11:06

1 Answers1

0

JavaScript uses objects to store date values. When you want to compare if two dates are equal don't do this like date1 === date2. That will just tell you if the two variables reference the same object.

To check if two dates are equal use the getTime() method of the date object. Like this:

date1.getTime() == date2.getTime()

Be careful because any difference in seconds will fail to match the dates.

Now ng-if will accept AngularJS expressions. Ensure that both variables are valid JavaScript date objects.

I recommend that you use the moment javascript library for date processing. It makes working with dates a lot easier.