title: Objective C , comparing two dates
body: <p>I am trying to compare two dates but I can t see how it works at all ...</p>
  
  <p>this is the code that I am using :</p>
  
  <pre><code>   NSCalendar* myCalendar = [NSCalendar currentCalendar];
      NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
  
                                                   fromDate:[NSDate date]];
      [components setYear:2012];
      [components setMonth:03];
      [components setDay:25];
      NSDate *startDate = [myCalendar dateFromComponents:components];
  
  
      NSDateComponents* components2 = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
  
                                                   fromDate:[NSDate date]];
      [components2 setYear:2012];
      [components2 setMonth:04];
      [components2 setDay:25];
      NSDate *endDate = [myCalendar dateFromComponents:components];
  
      NSComparisonResult result1 = [now compare:startDate];
      NSComparisonResult result2 = [now compare:endDate];
  
      if (result2 &amp;&amp;
  
          result1
          ) {
          int x =1;
      }
  </code></pre>
  
  <p>the thing is even if the two dates are in the future , i still can get into the if condition ... any reason ?</p>