Created
January 3, 2014 17:59
-
-
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.
This file contains 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
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