Question

I want to find the future date after adding a number of days to another date.

So if I have this:

 NSDateComponents *pastDate = [[NSDateComponents alloc] init];
        [pastDate setMonth:12];
        [pastDate setDay:23];
        [pastDate setYear:2011];

and want to add 90 days to find the future date. What method should I be looking at? I got creating another variable. I'm interested in what method. Thanks.

Was it helpful?

Solution

You might start with an NSDate, set it up by calling:

NSDate* pastDate = [NSDate dateWithTimeIntervalSinceReferenceDate:kStartDate];
NSDate* newDate = [pastDate dateByAddingTimeInterval:kNumSecondsIn90Days];

and converting to an NSDateComponent as described here. (Note that you'll have to define kStartDate as the number of seconds since January 1st, 2001 to 12/23/2011. And you'll have to define kNumSecondsIn90Days.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top