Created
February 18, 2016 15:23
-
-
Save AdityaDeshmane/3220c03165cb55e5d472 to your computer and use it in GitHub Desktop.
iOS: Compare Dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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