2013-02-13 2 views

답변

2

- (NSPredicate *)predicateForDateWithinLast30Days 
{ 

    NSDate *currentDate = [NSDate date];// get the current date 


    // get the date 30 days prior to current date 

    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
    [dateComps setDay:-30]; 
    NSDate *date30DaysAgo = [calendar 
      dateByAddingComponents:dateComps 
      toDate:currentDate options:0]; 

    // create the predicate 
    NSPredicate *last30DaysPredicate = [NSPredicate 
      predicateWithFormat:@"dateToCompare > %@", date30DaysAgo]; 

    return last30DaysPredicate; 
} 
+0

, 감사 완벽하게 작동! – user2067051

+0

나는 다음 30 일 이내에를 제외하고 비슷한 것을 필요로했다. 조금 수정하고 큰 감사를 보냈습니다! – RyanG

+0

안녕하세요 친구 .. 전 개념을 술술에 익숙하지 않아요 ..이 개념을 구현해야합니다 .. 날짜에 따라 필터링해야하는 내 비용이 필요합니다 ..이 NSpredicate 메서드는 언제 호출 될 것입니다 ..이 구현하는 방법 .. – Mano

관련 문제