Compare Date & String

iPhone SDK Tips & Tricks

NSDateComponents *compsDisplay = [[NSDateComponents alloc] init];
[compsDisplay setDay:1];
[compsDisplay setMonth:9];
[compsDisplay setYear:2009];
NSCalendar *gregorianDisplay = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDate *dateDisplay = [gregorianDisplay dateFromComponents:compsDisplay];
NSDate *now = [NSDate date]; //today date

if([dateDisplay compare:now] == NSOrderedDescending)
{
NSLog(@”date display is bigger that now”);
}

NSComparisonResult:

NSOrderedAscending
NSOrderedDescending
NSOrderedSame