title: iOS: Compare two NSDate-s without time portion
body: <p>I want to compare two dates: date1 and date2</p>
  
  <pre><code>2011-06-06 12:59:48.994 Project[419:707] firstDate:2011-06-06 10:59:21 +0000
  2011-06-06 12:59:49.004 Project[419:707] selectedData:2011-06-06 10:59:17 +0000
  </code></pre>
  
  <p>but these dates have different time and when I use NSOrderedSame it don't work fine, how can I solve?</p>
  
  <p>my code:</p>
  
  <pre><code>NSDate *firstDate = [[appDelegate.project objectAtIndex:i]objectAtIndex:3];
  NSDate *secondDate = [[appDelegate.project objectAtIndex:i]objectAtIndex:4];
  
  NSCalendar *calendar = [NSCalendar currentCalendar];
  NSInteger comps = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit);
  
  NSDateComponents *date1Components = [calendar components:comps 
                                                              fromDate:firstDate];
  NSDateComponents *date2Components = [calendar components:comps 
                                                              fromDate:secondDate];
  NSDateComponents *date3Components = [calendar components:comps fromDate:appDelegate.selectedDate];
  
  NSLog(@"firstDate:%@", [date1Components date]);
  NSLog(@"secondDate:%@", [date2Components date]);
  NSLog(@"selectedData:%@", [date3Components date]);
  
  NSComparisonResult compareStart = [[date1Components date] compare: [date3Components date]]; 
  NSComparisonResult compareEnd = [[date2Components date] compare: [date3Components date]]; 
  
  if ((compareStart == NSOrderedAscending || compareStart == NSOrderedSame)
       &amp;&amp; (compareEnd == NSOrderedDescending || compareEnd == NSOrderedSame))
  
  {
      NSLog(@"inside");
  </code></pre>
  
  <p>Then I want to compare my dates and entry inside the "if" when  date1 &lt;= selectedDate &lt;= date2; now I understand because I have a warning: I should add this "[date1Components date]" and it work; the problem is that I have in the NSLog null values, why??</p>