I want to get a quarter value from specified date. (*date variable)
So. I have made following code and run. but, quarter value is zero.
Why quarter value is
It seems that there is an issue with the NSQuarterCalendarUnit being ignored (haven't verified, but did see a bug reported). Anyway, it is simple enough to get around... Just use the NSDateFormatter class.
// After your NSDate *date, add...
NSDateFormatter *quarterOnly = [[NSDateFormatter alloc]init];
[quarterOnly setDateFormat:@"Q"];
int quarter = [[quarterOnly stringFromDate:date] intValue];
// Then change the quarter NSLog too
NSLog(@"quarter : %5d", quarter);
Should work fine...
Dec 16 2014
How about simply:
([comp2 month]-1)/3+1;