-3

Possible Duplicate:
How do you calculate the day of the year for a specific date in Objective C

I am looking for a way to find the day number which has past in current year. For example if today was 2013-03-22 , then the number should be 81, because 81 day has past in 2013 year. It doesn't matter if it is a leap year or not.

So if anybody has some links or even a way how to do it, please share it with me. Thanks in advance!

Community
  • 1
  • 1
Lukas
  • 2,515
  • 4
  • 28
  • 37
  • 3
    http://stackoverflow.com/questions/2080927/how-do-you-calculate-the-day-of-the-year-for-a-specific-date-in-objective-c looks like an exact duplicate – s.bandara Jan 21 '13 at 08:07
  • Thanks, tried googling it and finding it here in stackoverflow, but didn't managed to find this. This is exactly what i need. Thanks very much for your help! – Lukas Jan 21 '13 at 08:12
  • you can try using the unix timestamp as it is universal ... u can then manipulate any date using that – madLokesh Jan 21 '13 at 08:16

2 Answers2

1

Try this:

NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSInteger dc = [currentCalendar  ordinalityOfUnit:NSDayCalendarUnit
                                                  inUnit:NSYearCalendarUnit
                                                 forDate:today];
spaleja
  • 1,435
  • 15
  • 24
-3

You can this by

NSDate *date1 = [NSDate dateWithString:@"2010-01-01 00:00:00 +0000"];
NSDate *date2 = Your END Date / Today's date may be;

NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];

int numberOfDays = secondsBetween / 86400;

NSLog(@"No of days passed since new year.", numberOfDays);
Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45