title: Core Data NSPredicate not returning records between two dates
body: <p>I have a CoreData entity <code>Comment</code> who has a parent entity <code>Measurement</code>.</p>
  
  <p>The <code>Measurement</code> entity has a <code>measurementDate</code> attribute.  </p>
  
  <p>My Core Data database has 200 <code>Comment</code> records in it, each with varying <code>measurementDate</code> values over the last 3 years.</p>
  
  <p>I'm trying to get the records where <code>measurementDate</code> is between any two given dates.</p>
  
  <p>Firstly, I tried this:</p>
  
  <pre><code>//now fetch a record between 12 and 11 months ago
  NSDate *startDate = [AppGlobals dateByAddingMonths:[NSDate date] withMonths:-12];
  NSDate *endDate = [AppGlobals dateByAddingMonths:startDate withMonths:1];
  
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(measurementDate &gt;= %@) AND (measurementDate &lt;= %@)", startDate, endDate];
  
  NSFetchRequest *request = [[NSFetchRequest alloc] init];
  [request setEntity:[NSEntityDescription entityForName:@"Comment" inManagedObjectContext:self.context]];
  [request setPredicate:predicate];
  
  NSError *error = nil;
  NSArray *results = [self.context executeFetchRequest:request error:&amp;error];
  </code></pre>
  
  <p>But I got 0 results.</p>
  
  <p>So then I tried replacing my predicate with something simpler:</p>
  
  <pre><code>NSPredicate *predicate = [NSPredicate predicateWithFormat:@"measurementDate &gt;= %@", startDate];
  </code></pre>
  
  <p>This should return approximately a third of my results.  But actually it returns ALL 200 RECORDS.</p>
  
  <p>I've logged out the dates of the objects and it looks like the dates are being completely ignored!  </p>
  
  <p>What am I doing wrong???</p>
  
  <p>Is it something to do with the Parent Abstract entity <code>Measurement</code> and because I'm fetching from the <code>Comment</code> entity and not the <code>Measurement</code> entity?
  Is it because I'm using "scalar properties for primitive data types"  in my code?  </p>
  
  <p>Any help greatly appreciated.</p>