Skip to content

Instantly share code, notes, and snippets.

@coryhymel
Created October 10, 2012 20:15
Show Gist options
  • Save coryhymel/3868125 to your computer and use it in GitHub Desktop.
Save coryhymel/3868125 to your computer and use it in GitHub Desktop.
Find number of days between two NSDates
- (NSInteger)daysBetweenDate:(NSDate*)fromDateTime andDate:(NSDate*)toDateTime
{
NSDate *fromDate;
NSDate *toDate;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&fromDate
interval:NULL forDate:fromDateTime];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&toDate
interval:NULL forDate:toDateTime];
NSDateComponents *difference = [calendar components:NSDayCalendarUnit
fromDate:fromDate toDate:toDate options:0];
return [difference day];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment