This is my code
NSDateFormatter *dfPeriod = [[NSDateFormatter alloc] init];
[dfPeriod setDateFormat:REPORT_PERIOD1];
m_dpReportFromDate=[[UIDatePicker alloc]initWithFrame:CGRectMake(25, 55, 300, 200)];
m_dpReportFromDate.datePickerMode=UIDatePickerModeDate;
if(m_strFromDate.length>0)
m_dpReportFromDate.date=[dfPeriod dateFromString:m_strFromDate];
[self.view addSubview:m_dpReportFromDate];