UIDatePicker *_datePickerView = [[UIDatePicker alloc] initWithFrame:CGRectZero];
_datePickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
_datePickerView.datePickerMode = UIDatePickerModeDate;
CGRect pickerRect = CGRectMake( 0.0, 480, 320, 250);
_datePickerView.frame = pickerRect;
_datePickerView.hidden = YES;
_datePickerView.datePickerMode = UIDatePickerModeDate;
// in case we previously chose the Counter style picker, make
sure
// the current date is restored
NSDate *today = [NSDate date];
_datePickerView.date = today;
_datePickerView.datePickerMode = UIDatePickerModeDate;
[_datePickerView addTarget:self action:@selector(updateLabel:) forControlEvents:UIControlEventValueChanged];
[parent.view addSubview:_datePickerView];
-(void)updateLabel:(id)sender
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
NSCalendar *calendar = [NSCalendar currentCalendar];
int year = [[calendar components:NSYearCalendarUnit fromDate:[_datePickerView date]] year];
int month = [[calendar components:NSMonthCalendarUnit fromDate:[_datePickerView date]] month];
int day = [[calendar components:NSDayCalendarUnit fromDate:[_datePickerView date]] day];
NSString *date = [NSString stringWithFormat:@"%d/%d/%d",year,
month, day];//[df
stringFromDate:_datePickerView.date]];
[_birthdayLabel setTitle:date forState:UIControlStateNormal];
/* the following allows you to choose the date components
NSCalendar *calendar = [NSCalendar currentCalendar];
int hour = [[calendar
components:NSHourCalendarUnit
fromDate:[datePicker date]] hour];
int minute =
[[calendar components:NSMinuteCalendarUnit fromDate:[datePicker date]] minute];
int year = [[calendar
components:NSYearCalendarUnit
fromDate:[datePicker date]] year];
int month = [[calendar
components:NSMonthCalendarUnit
fromDate:[datePicker date]] month];
int day = [[calendar
components:NSDayCalendarUnit fromDate:[datePicker date]] day];
*/
}