I need to compare the current date/time against user selected date/time. Below is my code snippet
-(IBAction)btnSaveTouched:(id)sender {
NSDate *today = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd H:mm"];
NSString *formatterDate = [formatter stringFromDate: today];
NSComparisonResult comparisionResult1 = [self.paramSchedule1StartSQLDateString compare:formatterDate];
if (comparisionResult1 == NSOrderedAscending) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Viewing schedule must be after current time." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
NSLog(@"comparisionResult1 %d", comparisionResult1);
}
After btnSaveTouched(UIButton) is tap, the date/time will be store into the database and return back to the screen. (view controller where user select the date/time)
However, when I tried to compare another date/time, the alert will be show even though I selected date/time later then the current date/time.
After NSLog the comparsionResult1, the value is 1 for the second time checking always. I tried to do this NSComparsionResult comparisionResult1 = 0; but it's not working properly. Is there any ways to go about doing this?
Please advise. Thanks