My question is the REVERSE of the typical "How do I find out if an NSDate is between startDate and endDate?"
What I want to do is find ALL NSDATES (to the day, not hour or minute) that occur BETWEEN startDate and endDate. Inclusive of those dates would be preferable, although not necessary.
Example: (I know that these don't represent NSDates, these are just for illustration)
INPUT: startDate = 6/23/10 20:11:30 endDate = 6/27/10 02:15:00
OUTPUT: NSArray of: 6/23/10, 6/24/10, 6/25/10, 6/26/10, 6/27/10
I don't mind doing the work. It's just that I don't know where to start in terms of making efficient code, without having to step through the NSDates little by little.
Use an NSCalendar
instance to convert your start NSDate
instance into an NSDateComponents
instance, add 1 day to the NSDateComponents
and use the NSCalendar
to convert that back to an NSDate
instance. Repeat the last two steps until you reach your end date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With