I am using the following code to find from current date+time to 30 days future. It works fine. But, i want now the end date should be 60 days, not 30 days. How can i change the below code to get upto 60 days? I tried changing end date to [currentDateComponents month]+1, but its not working. Any help please?
NSDate *date = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *currentDateComponents = [gregorian components:( NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSWeekCalendarUnit) fromDate:date];
NSLog(@"- current components year = %d , month = %d , week = % d, weekday = %d", [currentDateComponents year], [currentDateComponents month], [currentDateComponents week], [currentDateComponents weekday]);
NSArray* calendars = [[CalCalendarStore defaultCalendarStore] calendars];
NSLog(@"calendars.count: %ld", [calendars count]);
debug(@"LogMsg:%@ Date:%@", @"Start looking for new events for pushing iCal to OfferSlot", [NSDate date]);
// 30 days any new or modified calendar (iCal) events will be pushed here to OfferSlot
NSInteger year = [[NSCalendarDate date]yearOfCommonEra];
NSDate *startdate = [NSCalendarDate dateWithYear:year month:[currentDateComponents month] day:1 hour:0 minute:0 second:0 timeZone:nil];
NSDate *enddate = [NSCalendarDate dateWithYear:year month:[currentDateComponents month] day:31 hour:23 minute:59 second:59 timeZone:nil];
Your code does not always do what you describe in the text. It creates two dates, one at the beginning of the current month, one at the end of the month (if the month has 31 days, if it has less than 31 days your endDate will be in the next month). If you run the code on the 1st of each month it will create a NSDate that is 30 days in the future, but only on the 1st of each month.
if you really want to get the NSDate that is 60 days from now use this code: