Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:43:53+00:00 2026-06-08T07:43:53+00:00

I want to get a quarter value from specified date. (*date variable) So. I

  • 0

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 zero?
where’s problem?

Please advice from advanced man.

NSDateComponents *comp1 = [[NSDateComponents alloc] init];
[comp1 setYear:2012];
[comp1 setMonth:6];
[comp1 setDay:1];

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDate *date = [gregorian dateFromComponents:comp1];  <== want to get a quarter value.

unsigned int unitFlags = NSYearCalendarUnit | NSQuarterCalendarUnit | NSMonthCalendarUnit | NSWeekOfYearCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *comp2 = [gregorian components:unitFlags fromDate:date];

NSLog(@"year :       %5d",[comp2 year]);
NSLog(@"quarter :    %5d",[comp2 quarter]);
NSLog(@"month :      %5d",[comp2 month]);
NSLog(@"weekofYear : %5d",[comp2 weekOfYear]);
NSLog(@"day :        %5d",[comp2 day]);

Result:

2012-07-24 03:44:14.776 dateTest[1228:1307] year :        2012
2012-07-24 03:44:14.776 dateTest[1228:1307] quarter :        0
2012-07-24 03:44:14.777 dateTest[1228:1307] month :          6
2012-07-24 03:44:14.777 dateTest[1228:1307] weekofYear :    22
2012-07-24 03:44:14.778 dateTest[1228:1307] day :            1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:43:56+00:00Added an answer on June 8, 2026 at 7:43 am

    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…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want get exeption code from wcf method but i always get NotFound error.
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I want get data in db to listview. but it have error I cannot
I want get from database table row name but in it i get error.
I have a field with value of holmes@sible.com I want get back this field
I want get as much as possible from Redis + Hiredis + libevent. I'm
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
I want get only the starting html tags. Lets say I have html like
I want get the most specific from the current url in visual basic .net.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.