Skip to content

Instantly share code, notes, and snippets.

@nickplace
Created January 3, 2014 17:59
Show Gist options
  • Save nickplace/8242890 to your computer and use it in GitHub Desktop.
Save nickplace/8242890 to your computer and use it in GitHub Desktop.
#Find the number of midnights between two dates Apple's prescribed way of getting the number of days between two days (using dateComponents) was being very unreliable for me so I had to come up with my own solution for finding the number of midnights between two dates.
NSDate startDate = ...;
NSDate endDate = ...;
NSTimeInterval startDays = ceil( [startDate timeIntervalSince1970] / 86400); // there are 86400 seconds in a day
NSTimeInterval endDays = ceil ( [endDate timeIntervalSince1970] / 86400);
int days = endDays - startDays;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment