views:

227

answers:

4

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

A: 
datePicker.datePickerMode = UIDatePickerModeDate;

From the documentation:

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

Ole Begemann
A: 

thanks for the tip, but my problem is different. I want to get the date with [NSDate date] method, but I need only the date and non the complete timestamp.

Andrea Mattiuz
A: 

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

Anyways.. see NSDateFormatter

lukya
A: 

I believe that your answer can be found in this previous question: http://stackoverflow.com/questions/936969/nsdate-and-nsdateformatter-short-format-date-and-time-in-iphone-sdk

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];
bjtitus
thanks to all,these tips were very useful!!
Andrea Mattiuz