I need to retrieve all Booking objects with departDate property set to current date or future date. My code is as below:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(departDate >= %@)", [NSDate date]];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
NSError *error;
bookings = [[context executeFetchRequest:fetchRequest error:&error] retain];
NSLog(@"curernt date %@", [NSDate date]);
for (Booking *order in bookings) {
NSLog(@"%@", [NSDate dateWithTimeIntervalSince1970:order.departDate]);
}
But the log shows:
2012-03-06 18:58:24.518 Airline[2201:207] curernt date 2012-03-06 13:28:24 +0000
2012-03-06 18:58:24.520 Airline[2201:207] 2012-03-06 12:37:59 +0000
2012-03-06 18:58:24.528 Airline[2201:207] 2012-03-05 12:55:50 +0000
2012-03-06 18:58:24.529 Airline[2201:207] 2012-03-08 12:55:50 +0000
2012-03-06 18:58:24.530 Airline[2201:207] 2012-03-02 13:07:33 +0000
2012-03-06 18:58:24.531 Airline[2201:207] 2012-04-06 13:13:53 +0000
2012-03-06 18:58:24.532 Airline[2201:207] 2012-01-06 13:13:53 +0000
All the objects are being retrieved as if there is no filters. Could some one please tell me what I am doing wrong here?
Core Data support dates directly as
NSDate. You’ve mixing usingNSDateand the date as seconds since 1970.In your model, make sue
departDateis set to be a “Date”, then use