Created
March 28, 2014 16:45
-
-
Save jonahsiegle/9837352 to your computer and use it in GitHub Desktop.
Check if two NSDate objects are on the same day.
This file contains 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)isSameDayWithDateOne:(NSDate *)dateOne dateTwo:(NSDate *)dateTwo{ | |
NSCalendar *calender = [NSCalendar currentCalendar]; | |
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; | |
NSDateComponents *compOne = [calender components:unitFlags fromDate:dateOne]; | |
NSDateComponents *compTwo = [calender components:unitFlags fromDate:dateTwo]; | |
return ([compOne day] == [compTwo day] && [compOne month] == [compTwo month] && [compOne year] == [compTwo year]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this - I just turned it in to a swift extension https://gist.github.com/lukewakeford/4e6cda958c252017e112