how can I compare two dates return number of days. Ex: Missing X days of the Cup. look my code.
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"d MMMM,yyyy"];
NSDate *date1 = [df dateFromString:@"11-05-2010"];
NSDate *date2 = [df dateFromString:@"11-06-2010"];
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
//int days = (int)interval / 30;
//int months = (interval - (months/30)) / 30;
NSString *timeDiff = [NSString stringWithFormat:@"%dMissing%d days of the Cup",date1,date2, fabs(interval)];
label.text = timeDiff; // output (Missing X days of the Cup)
You can use next category:
From Apple's example, basically use an NSCalendar:
Try this category:
You can use this category by adding an import:
And call it from your code:
Need to call this method and set 2 dates only which we want to calculate differently.