How to compare current date to previous date in iphone?

ios, iphone, nsdate, xcode

Solution

NSDate *today = [NSDate date]; // it will give you current date
NSDate *newDate = [dateFormatter dateWithString:@"xxxxxx"]; // your date 

NSComparisonResult result; 
//has three possible values: NSOrderedSame,NSOrderedDescending, NSOrderedAscending

result = [today compare:newDate]; // comparing two dates

if(result==NSOrderedAscending)
    NSLog(@"today is less");
else if(result==NSOrderedDescending)
    NSLog(@"newDate is less");
else
    NSLog(@"Both dates are same");

got your solution from this answer How to compare two dates in Objective-C

Problem

I would like to compare the current date with another date, and if that is date is earlier than the current date, then I should stop the next action. How can I do this? I have todays date in `yyyy-MM-dd` format. I need to check this condition ``` if([displaydate text]<currentdate) { //stop next action } ``` Here if `displaydate` is less than todays date then it has to enter that condition.

Original source

Related problems