Use NSDateComponents, something like this:
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *today = [NSDate date];
NSDateComponents *todaysComponents =
[gregorian components:NSWeekCalendarUnit fromDate:date];
NSUInteger todaysWeek = [todaysComponents week];
NSDate *anotherDate = [NSDate date];
NSDateComponents *otherComponents =
[gregorian components:NSWeekCalendarUnit fromDate:anotherDate];
NSUInteger anotherWeek = [otherComponents week];
if(todaysWeek==anotherWeek){
NSLog(@"another date is this week");
}else if(todaysWeek+1==anotherWeek){
NSLog(@"another date is next week")
}
You can also fully use other components, such as a month or a year.
NOTE: Do not use timeIntervals. Using NSDateComponents, you ignore hours, minutes, and seconds. I think you want it.
source
share