Created
August 29, 2012 06:43
-
-
Save nilaft/3507559 to your computer and use it in GitHub Desktop.
Check NSDate difference in days
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
+ (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