How to disable past dates in Android date picker?

You can do

datePicker.setMinDate(System.currentTimeMillis() - 1000);

which sets today's date as minimum date and all the past dates are disabled.

datePicker is an object of DatePicker if you are using an object of DatePickerDialog you can do

datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);

Note: setMinDate was introduced in API 11


This method will work properly.

//Get yesterday's date
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);

//Set yesterday time milliseconds as date pickers minimum date
DatePickerDialog datePickerDialog = new DatePickerDialog(context, myDateListener, year, month, day);
datePickerDialog.getDatePicker().setMinDate(calendar.getTimeInMillis());
datePickerDialog.show();

Tags:

Android