Reputation: 183
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *dateStart = [calendar components:unitFlags fromDate:start];
quarterStart = [dateStart quarter];
NSDateComponents *dateEnd = [calendar components:unitFlags fromDate:end];
quarterEnd = [dateEnd quarter];
Having two NSDate start and end and extracting start quarter and end quarter i need to know the differences in quarters between these 2 dates.
I know that i could divide the total days / 90 days but i'm looking at another solution having only these data.
Any hints ?
Upvotes: 0
Views: 352
Reputation: 183
I've solved using that, cause the other suggested answer not works for an Apple's bug on quarter Unit.
numberOfQuarters = (4 - startQuarter) + ((endYear -1 - startYear) * 4) + endQuarter;
Upvotes: 0
Reputation: 2796
You should try:
NSDateComponents *result = [[NSCalendar currentCalendar] components:NSQuarterCalendarUnit fromDate:start toDate:end options:0];
NSInteger numberOfQuaters = [result quarter];
Upvotes: 2