In my project i need to show the date picker 18 back and i need to lock the 80 years backs so how can i show those date in datepicker can any one help me to find here here am adding code my code i printed in log but i need to display on my datepicker so how can i display
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate * currentDate = [NSDate date];
NSDateComponents * comps = [[NSDateComponents alloc] init];
[comps setYear: -18];
NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[comps setYear: -100];
NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[comps release];
self.datePickerView.minimumDate = minDate;
self.datePickerView.maximumDate = maxDate;
NSLog(@"minDate %@", minDate);
NSLog(@"maxDate%@", maxDate);
Hi first of all minimum date must be 100 year back date and max date must be 18 year back date and then set pickerView's date to a date between range of dates so your final code will be looks like
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate * currentDate = [NSDate date];
NSDateComponents * comps = [[NSDateComponents alloc] init];
[comps setYear: -18];
NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[comps setYear: -100];
NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[comps release];
self.datePickerView.minimumDate = minDate;
self.datePickerView.maximumDate = maxDate;
self.datePickerView.date = minDate;
Hopefully this will be helpful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With