Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to disable saturday and sunday from datepickerdialog

How to disable saturday and sunday from datepickerdialog in xamarin android. Here I provided only mindate but not max date. and I am getting the business days by using the following code.
public double getbusinessdays(DateTime stdate, DateTime eddate)
double businessdays = 1 + ((eddate - stdate).TotalDays * 5 - (stdate.DayOfWeek - eddate.DayOfWeek) * 2) / 7;
if(eddate.DayOfWeek == DayOfWeek.Saturday) {
if(stdate.DayOfWeek == DayOfWeek.Sunday)
return businessdays;

But Now I want to disable the saturday and sunday.



  • Moses_SundayMoses_Sunday Member ✭✭

    You can do it by using given code.

    if (dateTimePicker1.Text.Contains("Saturday")) { dateTimePicker1.Text = dateTimePicker1.Value.AddDays(2).ToString(); } else if(dateTimePicker1.Text.Contains("Sunday")) { dateTimePicker1.Text = dateTimePicker1.Value.AddDays(1).ToString(); }

    How to stop a user by selecting saturday and sunday.
    simple by Passing Message to user

    if (dateTimePicker1.Text.Contains("Saturday") || dateTimePicker1.Text.Contains("Sunday")) { // Pass Message Here }

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 2019

    Traditional datepicker Calender doesn't support to disable all Sundays and Saturdays in calendar datepicker dialog so that nobody will be able to select disabled dates. Material Datepicker is a good choice to disable specific dates in Datepicker. It provides very useful methods to take Calander array of days like:

    setSelectableDays(Calendar[] days): The values in this list are the only acceptable dates for the picker.
    setDisabledDays(Calendar[] days): The values in this Calendar[] are explicitly disabled (not selectable).

    Sample code:

    DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(MainActivity.this, Year, Month, Day);
    datePickerDialog.setTitle("Date Picker");
    // Setting Min Date
    Calendar min_date_c = Calendar.getInstance();
    // Setting Max Date
    Calendar max_date_c = Calendar.getInstance();
    max_date_c.set(Calendar.YEAR, Year + 2);
    //Disable all SUNDAYS and SATURDAYS between Min and Max Dates
    for (Calendar loopdate = min_date_c; min_date_c.before(max_date_c); min_date_c.add(Calendar.DATE, 1), loopdate = min_date_c)
        int dayOfWeek = loopdate.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY)
            Calendar[] disabledDays = new Calendar[1];
            disabledDays[0] = loopdate;

    For more details, check the Tutorials:

Sign In or Register to comment.