title: DatePicker not selecting the correct date
body: <p>I have a <code>Button</code> in my <code>view</code>.On tapping the <code>Button</code> you get a <code>datepicker</code> which defaults to today's date, the user can then select the date they want to search for events.
  The problem is, no matter what date I select, it always returns the current day and adds this to my <code>TextField</code> which i have placed inside mu <code>Button</code>.Can any one tell me where I am wrong.am setting the date picker programatically.</p>
  
  <p>Below is my code hopefully someone can help me out!</p>
  
  <p>//displaying date picker while clicking on button</p>
  
  <pre><code> - (IBAction)startDateButtonAction:(id)sender
    {
       if ([popOverController isPopoverVisible]) {
      [popOverController dismissPopoverAnimated:YES];
    }
      UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
      UIView *popoverView1 = [[UIView alloc] init];   //view
      datePicker          =[[UIDatePicker alloc]init];//Date picker
      datePicker.frame    =CGRectMake(0,0,240, 150);
      datePicker.datePickerMode = UIDatePickerModeDate;
      [datePicker setMaximumDate:[[NSDate date] dateByAddingTimeInterval:24*60*60*-6]];
      [datePicker setMinimumDate:[DateFormatter getSubtractedDateForomCurrentDateWith:35]];
      datePicker.date     = [DateFormatter getDateFromString:startDateLabel.text];
      datePicker.selected = YES;
      [datePicker addTarget:self action:@selector(datePickerValue)       forControlEvents:UIControlEventValueChanged];
      [popoverView1 addSubview:datePicker];
      popoverContent.view = popoverView1;
      popOverController = [[UIPopoverController alloc]    initWithContentViewController:popoverContent];
      [popOverController setPopoverContentSize:CGSizeMake(240, 150) animated:NO];
      [popOverController presentPopoverFromRect:startDateButton.frame inView:headerView   permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
  }
  </code></pre>
  
  <p>//action function while selecting any of the date from date picker</p>
  
  <pre><code> - (void) datePickerValue
    {
       NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
       [offsetComponents setDay:-6]; 
       NSDate *labelStartDate = datePicker.date;
       startDate = [DateFormatter getOnlyDateComponentsFromDate:labelStartDate];
       NSDate *labelEndDate = [self addDayToDate:startDate Number:6];
       startDateLabel.text = [DateFormatter getDateStringddmmyyy:labelStartDate];
       endDateLabel.text   = [DateFormatter getDateStringddmmyyy:labelEndDate];
     }
  </code></pre>
  
  <p>[including the functions that am used here]</p>
  
  <pre><code>//used for getting date components
  +(NSDate *) getOnlyDateComponentsFromDate:(NSDate *)date
  {
  unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
  NSCalendar* calendar = [NSCalendar currentCalendar];
  NSDateComponents* components = [calendar components:flags fromDate:date];
  NSDate* dateOnly = [calendar dateFromComponents:components];
  return dateOnly;
  }  
  
  
   - (NSDate *) addDayToDate:(NSDate *)date Number:(int) number
  {
    NSDate *newDate = [date dateByAddingTimeInterval:60*60*24*number];
    return newDate;
  }
  </code></pre>
  
  <p>Iam using ARC.
  here <code>datePicker.date</code> gives me only the current date even though I select any other dates</p>