Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xmax

macrumors member
Original poster
Jul 3, 2008
33
0
Hello,
I want to get week number and day number from given date.
Say Given date is "2009-03-12 16:11:09 +0530". On providing this date, it should give me result second thursday i.e 2 for second and 5 for thursday.
I am trying to get it using NSDateComponents and NSDayCalendarUnit.

Is it possible to have a day and week number for particular date ?


Thanks.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Yes, or them together like NSDayCalendarUnit | NSWeekCalendarUnit and then the returned NSDateComponents object will contain values for both.
 

xmax

macrumors member
Original poster
Jul 3, 2008
33
0
I got 5 i.e day number. but i am not getting week number.
I have done this much on getting day number
NSCalendar *gregorian = [NSCalendar currentCalendar];
NSDateComponents *weekDayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:aDate];
NSInteger mDay = [weekDayComponents weekday];
NSLog(@"day number = %d" , mDay);


I am not getting week number.




Thanks.
 

xmax

macrumors member
Original poster
Jul 3, 2008
33
0
Yes, but it gives me the week number for year that is 11.
But we need week number for that month only i.e 2.


so, is there any way ot get it?


Thanks
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Ok this is basic logic. If those two values don't give you what you want, look at the documentation and/or header file and see if there is another one that does.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.