locked
How to disable(cannot access) previous month dates from 1st july 2019 date in datepicker. RRS feed

  • Question

  • User306227 posted

    How to disable(cannot access) previous month dates from 1st july 2019 date in datepicker.

    Thursday, April 30, 2020 10:04 AM

Answers

  • User380187 posted

    Hi @Amejack , you can set MinimumDatefor UIDatePicker as follow :

    MyDatePciker.Mode = UIDatePickerMode.Date;
    
    var calendar = new NSCalendar(NSCalendarType.Gregorian);
    var currentDate = NSDate.Now;
    
    NSDateFormatter miniDateFormat = new NSDateFormatter();
    miniDateFormat.DateFormat = "yyyy-MM-dd";
    var miniDate = miniDateFormat.Parse("2019-07-01");
    var components = new NSDateComponents();
    components.Year = 0;
    NSDate minDate = calendar.DateByAddingComponents(components, miniDate, NSCalendarOptions.None);
    
    MyDatePciker.MinimumDate = minDate; // set  mini date
    MyDatePciker.MaximumDate = currentDate; // set max data 
    

    The effect :

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 4, 2020 9:33 AM

All replies

  • User380187 posted

    Hi @Amejack , could you share more explains about disable previous month dates from 1st july 2019 date in datepicker ? Such as with sharing an image here .

    Friday, May 1, 2020 1:36 AM
  • User306227 posted

    I don't have image.. I need to set min and max date.. I need to set 1st july 2019 to 31 may 2020..

    Friday, May 1, 2020 7:03 AM
  • User380187 posted

    Okey @Amejack , I will test that in local site . If achieve that will update here .

    Friday, May 1, 2020 9:09 AM
  • User306227 posted

    ok

    Friday, May 1, 2020 10:44 AM
  • User380187 posted

    Hi @Amejack , you can set MinimumDatefor UIDatePicker as follow :

    MyDatePciker.Mode = UIDatePickerMode.Date;
    
    var calendar = new NSCalendar(NSCalendarType.Gregorian);
    var currentDate = NSDate.Now;
    
    NSDateFormatter miniDateFormat = new NSDateFormatter();
    miniDateFormat.DateFormat = "yyyy-MM-dd";
    var miniDate = miniDateFormat.Parse("2019-07-01");
    var components = new NSDateComponents();
    components.Year = 0;
    NSDate minDate = calendar.DateByAddingComponents(components, miniDate, NSCalendarOptions.None);
    
    MyDatePciker.MinimumDate = minDate; // set  mini date
    MyDatePciker.MaximumDate = currentDate; // set max data 
    

    The effect :

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 4, 2020 9:33 AM
  • User306227 posted

    thanks a lot

    Monday, May 4, 2020 10:10 AM