Skip to content

Instantly share code, notes, and snippets.

@holysin
Created June 26, 2014 05:53
Show Gist options
  • Save holysin/2dbbfa3d9ccda940a7f9 to your computer and use it in GitHub Desktop.
Save holysin/2dbbfa3d9ccda940a7f9 to your computer and use it in GitHub Desktop.

Revisions

  1. holysin created this gist Jun 26, 2014.
    17 changes: 17 additions & 0 deletions DaysBetweenDates.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    + (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];
    }