5

How can I get only the date from a DatePicker component on iPhone? (better with a specific format).

Andrea Mattiuz
  • 89
  • 1
  • 2
  • 8

3 Answers3

17

I believe that your answer can be found in this previous question: Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

Just take the date you get back from the datePicker and get just the day using NSDateFormatter:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSString *theDate = [dateFormat stringFromDate:pickerDate];
[dateFormat release];
Community
  • 1
  • 1
bjtitus
  • 4,231
  • 1
  • 27
  • 35
2
datePicker.datePickerMode = UIDatePickerModeDate;

From the documentation:

The exact order of these items depends on the locale setting.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
1

In your question you mention you want it from DatePicker component!

Anyways.. see NSDateFormatter

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58