0

Possible Duplicate:
UIDatePicker, setting maximum and minimum dates based on todays date

I have tried allot but not able to give any range to uidatepicker, specifically maximum range as current date. No matter what I do the picker always shows all the values.

Thanks in advance

Community
  • 1
  • 1
  • See also [iPhone UIDatePicker setMaximumDate](http://stackoverflow.com/questions/3596987/iphone-uidatepicker-setmaximumdate) – Brad Larson Jul 05 '12 at 20:42

2 Answers2

2

here's a possible answer for setting the datepicker for 30 years before and 30 years after.

you can change the values for that..

NSCalendar *calendar = [[[NSCalendar alloc] 
initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setYear:30];
NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[comps setYear:-30];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];

[datePicker setMaximumDate:maxDate];
[datePicker setMinimumDate:minDate];

hope this helps..

iremk
  • 677
  • 1
  • 5
  • 16
  • 1
    And you ... you should post your source instead of copy and past http://stackoverflow.com/questions/3064864/uidatepicker-setting-maximum-and-minimum-dates-based-on-todays-date – Pierre Jul 05 '12 at 13:57
1

Hum you really should read the documentation. UIDatePicker have two properties : maximumDate and minimumDate ... Both of them are NSDate object. Enjoy !

Pierre
  • 10,593
  • 5
  • 50
  • 80