views:

207

answers:

2

Hi, I am trying to build a datepicker which has today as a minimum date and 1 Feb 2011 as Maximum date.

I have set the minimum date as followed

[picker setMinimumDate: [NSDate date]];

and this works just fine but the MaximumDate does not seem to be correct.

[picker setMaximumDate: [NSDate dateWithNaturalLanguageString:@"11/02/01"]];

How do I set the maximum date correctly?

+2  A: 

Found the answer. Thanks anyway for your help.

[picker setDatePickerMode:UIDatePickerModeDate];

NSDateFormatter* formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setLenient:YES];
[formatter1 setDateStyle:NSDateFormatterShortStyle];
[formatter1 setTimeStyle:NSDateFormatterShortStyle];

NSString* dateString = @"February 1 2011 10:00am";
NSDate* maxDate = [formatter1 dateFromString:dateString];

[picker setMinimumDate: [NSDate date]];
[picker setMaximumDate: maxDate];
Matthew Pateman
Hey @Matthew, set it as the correct answer so! Click on the check mark.
vfn
it wont let me do that for another 2 days - so I will do it then :D
Matthew Pateman
+1  A: 

You can also do it in Interface Builder's palette. I think if you press "Command-1" it will switch to a tab in the palette that allows you to set the Maximum date for the picker.

OOProg