title: Directive for comparing two dates
body: <p>I have used following code for directive which compares two dates (reference <a href="https://stackoverflow.com/questions/20982751/custom-form-validation-directive-to-compare-two-fields">Custom form validation directive to compare two fields</a>)</p>
  
  <pre><code>define(['./module'], function(directives) {
  'use strict';
  directives.directive('lowerThan', [
   function() {
  
     var link = function($scope, $element, $attrs, ctrl) {
     ctrl.$setValidity('lowerThan', false);
     var validate = function(viewValue) {
      var comparisonModel = $attrs.lowerThan;                
  
      /*if(!viewValue || !comparisonModel){
        // It's valid because we have nothing to compare against
        //console.log("It's valid because we have nothing to compare against");
        ctrl.$setValidity('lowerThan', true);
      }*/
  
      // It's valid if model is lower than the model we're comparing against
      //ctrl.$setValidity('lowerThan', parseInt(viewValue, 10) &lt;    parseInt(comparisonModel, 10) );        
      if(comparisonModel){       
          var to = comparisonModel.split("-");        
          var t = new Date(to[2], to[1] - 1, to[0]);
      }
      if(viewValue){
        var from=viewValue.split("-");
        var f=new Date(from[2],from[1]-1,from[0]);
      }
  
      console.log(Date.parse(t)&gt;Date.parse(f));
      ctrl.$setValidity('lowerThan', Date.parse(t)&gt;Date.parse(f));        
      return viewValue;
    };
  
    ctrl.$parsers.unshift(validate);
    ctrl.$formatters.push(validate);
  
    $attrs.$observe('lowerThan', function(comparisonModel){
      // Whenever the comparison model changes we'll re-validate
      return validate(ctrl.$viewValue);
    });
  
  };
  
  return {
    require: 'ngModel',
    link: link
  };
  
   }
   ]);
   });
  </code></pre>
  
  <p>but when page is loaded first time it displays error message. i have tried using ctrl.$setValidity('lowerThan', false); to make it invisible first time. but it is not working. </p>
  
  <p>Here is plunker for the same.
  <a href="http://plnkr.co/edit/UPN1g1JEoQMSUQZoCDAk?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/UPN1g1JEoQMSUQZoCDAk?p=preview</a></p>