All Objects from core data
{
dtStartDate = "Jun 10, 2016-10:40 AM";
},
{
dtStartDate = "May 12, 2016-06:55 AM";
},
{
dtStartDate = "May 12, 2016-08:05 AM";
},
{
dtStartDate = "May 12, 2016-02:30 PM";
},
{
dtStartDate = "Jun 12, 2016-07:50 AM";
},
{
dtStartDate = "Jul 12, 2016-08:50 AM";
},
{
dtStartDate = "Jun 12, 2016-07:50 AM";
},
{
dtStartDate = "May 12, 2016-10:00 AM";
},
{
dtStartDate = "Jun 12, 2016-07:30 AM";
}
I use this date format to predicate core data
NSDate *dt = [NSDate date];
NSDateFormatter *df =[[NSDateFormatter alloc] init];
[df setDateFormat:@"MMM dd, yyyy-hh:mm a"];
NSString *today =[df stringFromDate:dt];
NSDate *dateOfToday = [df dateFromString:today];
NSMutableArray *meetings=nil;
Now i have two conditions Fetch Date of future (including Current) and fetch date of past
Fetch Date of Future (including Today)
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dtStartDate >= %@",dateOfToday];
NSMutableArray *meetingsArr = [[CoreDataAPI sharedInstance] checkForRecordExistInTable:@"Tbl_Meeting" withCompountPredicate:[NSArray arrayWithObjects:predicate, nil]];
Return 9 Object (ALL) WRONG
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dtStartDate <= %@",dateOfToday];
NSMutableArray *meetingsArr = [[CoreDataAPI sharedInstance] checkForRecordExistInTable:@"Tbl_Meeting" withCompountPredicate:[NSArray arrayWithObjects:predicate, nil]];
Return 0 Object (nil) WRONG
Please help me to solve it Thanks in Advance
i can manually do it with this method and working. But i only want to do with predicate
-(NSMutableArray *)filterMeetingsBasedOnTime:(BOOL)isPastMtng :(NSMutableArray*)arr
{
NSDate *dt = [NSDate date];
NSDateFormatter *df =[[NSDateFormatter alloc] init];
[df setDateFormat:@"MMM dd, yyyy-hh:mm a"];
NSMutableArray *arrMeeting = [[NSMutableArray alloc] init];
for(NSDictionary *sMtngDict in arr)
{
NSDate *meetDate = [df dateFromString:[sMtngDict valueForKey:@"dtStartDate"]];
if(isPastMtng)
{
if([meetDate timeIntervalSinceDate:dt]<0)
{
[arrMeeting addObject:sMtngDict];
}
}
else{
if([meetDate timeIntervalSinceDate:dt]>=0)
{
[arrMeeting addObject:sMtngDict];
}
}
}
return arrMeeting;
}
can we use this method logic in predicate if yes then how ?