Vinay
Vinay

Reputation: 171

Fetching Dates Which Comes Between StartDate and EndDate

I am having array of dates and i need to fetch only those dates which comes between two differnt dates (StartDate and EndDate)..

can any one help me out in solving this... thanks in advance

Upvotes: 2

Views: 383

Answers (2)

graver
graver

Reputation: 15213

Assuming you have startDate and endDate instances of type NSDate you can:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF > %@) AND (SELF < %@)", startDate, endDate];
NSArray *result = [arrayWithDates filteredArrayUsingPredicate:predicate];

Upvotes: 4

MystikSpiral
MystikSpiral

Reputation: 5028

Check out filterWithPredicate, it allows you to create a filter rule to apply against all elements in the array.

Upvotes: 0

Related Questions