I want to set the minimum date the user can choose in a DatePicker to the current date. I\'ve tried this:
DatePicker datePicker = (DatePicker) findViewById(R
Check the Android DatePickerDialog set minimum and maximum date code.
Here is the examples.
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dpd = new DatePickerDialog(getActivity(),AlertDialog.THEME_TRADITIONAL,this,year, month, day);
//Get the DatePicker instance from DatePickerDialog
DatePicker dp = dpd.getDatePicker();
//Set the DatePicker minimum date selection to current date
dp.setMinDate(c.getTimeInMillis());//get the current day
//dp.setMinDate(System.currentTimeMillis() - 1000);// Alternate way to get the current day
//Add 6 days with current date
c.add(Calendar.DAY_OF_MONTH,6);
//Set the maximum date to select from DatePickerDialog
dp.setMaxDate(c.getTimeInMillis());
//Now DatePickerDialog have 7 days range to get selection any one from those dates