How to search by date, date format 05/25/16

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Use NSDate . Creating dates on a string of a given format:

 NSDateFormatter *dateFormat = [NSDateFormatter new]; [dateFormat setDateFormat:@"dd.LL.yy"]; NSDate *date = [dateFormat dateFromString:@"25.05.16"]; 

Compare dates using the compare method:

 if ([date1 compare:date2] == NSOrderedDescending) { NSLog(@"date1 is later than date2"); } else if ([date1 compare:date2] == NSOrderedAscending) { NSLog(@"date1 is earlier than date2"); } else { NSLog(@"dates are the same"); } 

With this method at hand, the search is not difficult to do.

Useful link: NSDate Class Reference .

    Just like the search for any other field. Via NSPredicate

     let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yy" let date = dateFormatter.dateFromString(@"25.05.16") [NSPredicate predicateWithFormat:@"(date == %@)", date]]