Skip to content

Instantly share code, notes, and snippets.

@jonahsiegle
Created March 28, 2014 16:45
Show Gist options
  • Save jonahsiegle/9837352 to your computer and use it in GitHub Desktop.
Save jonahsiegle/9837352 to your computer and use it in GitHub Desktop.
Check if two NSDate objects are on the same day.
- (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]);
}
@lukewakeford
Copy link

Thanks for this - I just turned it in to a swift extension https://gist.github.com/lukewakeford/4e6cda958c252017e112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment