Possible Duplicates:
Comparing dates
How to compare two dates in Objective-C
i want to compare 2 strings who have a date format "11-06-2011" and "12-06-2011" for exemple. i want to see if the second date is greater than the first or not can you help me please ?
i tried this code
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-YYYY"];
NSDate *date1 = [dateFormat dateFromString:deparatureDateField.text];
NSDate *date2 = [dateFormat dateFromString:comebackDateField.text];
[dateFormat release];
NSTimeInterval timeInterval = [date1 timeIntervalSinceDate:date2];
if(timeInterval >= 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"come back date should be greater" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[alert show];
}
but i alwayse have an alert, NSTimeInterval timeInterval is alwayse NULL