-1

I have the following line of code which sets the content or a label to a date.

cell.birthdayLabel.text = [[GlobalBirthdaysEditor instance] getFormattedDateString:[birthday getDate]];

I need to find out in the year is equal to 1604 and, if so, not show it.

How can I pull the year from this object?

So, basically looking for code like this:

if (year == 1604)
    {
        //set the date without the year
    } else {
        cell.birthdayLabel.text = [[GlobalBirthdaysEditor instance] getFormattedDateString:[birthday getDate]];
    }

Thank you!

samiles
  • 3,768
  • 12
  • 44
  • 71

1 Answers1

0
NSDate *currentDate = [[GlobalBirthdaysEditor instance] getFormattedDateString:[birthday getDate]];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentDate]; 
// Get necessary date components

int month = [components month] //gives you month
int day = [components day] //gives you day
int year = [components year] // gives you year

if(year==1604)
{ 
    //Do nothing 
}
else
{
    //Do something
}

Please visit this page for further details

Hope it will help you.

Gaurav Rastogi
  • 2,145
  • 1
  • 14
  • 19
  • Please do not copy other answer word for word without adding anything of value to them. If you find another answer that you think would be useful, then vote to close the question as a duplicate so that we don't keep getting more and more copies of the same question. If you do not have enough reputation to vote to close yet, then you can flag it for moderator action or even just put the link to the other question/answer in a comment on the question. – lnafziger May 06 '13 at 17:46