Reputation: 3534
I have a list of birthdays. From the list of b'days, I need to select all the b'days which occurs in the next 30 days.
For example : Today's date is 07/13, then I need to list all the b'days which occurs between 07/13 and 08/13.
Is there any built in method to select the dates in this manner.
Thanks in advance
Upvotes: 0
Views: 207
Reputation: 3588
You can use NSPredicate
for this:
NSDate *now = [NSDate date];
NSDate *later = [now dateByAddingTimeInterval:(30*24*60*60)];
NSPredicate *pre = [NSPredicate predicateWithFormat:@"SELF >= %@ AND SELF <= %@", now, later];
NSArray *upcomingBirthdays = [birthdays filteredArrayUsingPredicate:pre];
Upvotes: 2
Reputation: 5367
You going to have to work the logic out for yourself, here is a link to "Date and Time Programming Guide". It contains some sample code to check if "Date" falls within a Week. Might be a good place to start.
Upvotes: 0