Skip to content

Instantly share code, notes, and snippets.

@AdityaDeshmane
Created February 18, 2016 15:23
Show Gist options
  • Select an option

  • Save AdityaDeshmane/3220c03165cb55e5d472 to your computer and use it in GitHub Desktop.

Select an option

Save AdityaDeshmane/3220c03165cb55e5d472 to your computer and use it in GitHub Desktop.
iOS: Compare Dates
- (BOOL) validateDateWithCurrentDate
{
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];//Set timezone to match with [NSDate date] format
_chosenDate = [dateFormatter dateFromString:_labelDateOfBirthSeleced.text];
NSComparisonResult dateComparison = [[NSCalendar currentCalendar] compareDate:[NSDate date]
toDate:_chosenDate
toUnitGranularity:NSCalendarUnitDay];//dont compare time factor
return dateComparison == NSOrderedDescending;//NSOrderedDescending -> _chosenDate is older than current date
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment