How to Disable future dates in Android date picker
Java Code :
mExpireDate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // To show current date in the datepicker final Calendar mcurrentDate = Calendar.getInstance(); int mYear = mcurrentDate.get(Calendar.YEAR); int mMonth = mcurrentDate.get(Calendar.MONTH); int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH); DatePickerDialog mDatePicker = new DatePickerDialog( EventRegisterActivity.this, new OnDateSetListener() { public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) { mcurrentDate.set(Calendar.YEAR, selectedyear); mcurrentDate.set(Calendar.MONTH, selectedmonth); mcurrentDate.set(Calendar.DAY_OF_MONTH, selectedday); SimpleDateFormat sdf = new SimpleDateFormat( getResources().getString( R.string.date_card_formate), Locale.US); mExpireDate.setText(sdf.format(mcurrentDate .getTime())); } }, mYear, mMonth, mDay); mDatePicker.setTitle(getResources().getString( R.string.alert_date_select)); mDatePicker.show(); } });
How to do it?
// date range picker $('. date_input'). daterangepicker({ autoUpdateInput: false, locale: { cancelLabel: 'Clear', format: 'DD-MM-YY' } });
Using the setMinDate(…) method on the DatePicker class to grey out and disable the selection of dates that occured before the time value passed as a parameter.
In the Flutter date range picker, you can enable or disable the past dates by using the enablePastDates property of the calendar. When setting the enablePastDates property value as false, you can't able to select the past dates.
Here is a complete solution where you can use <apex:input type="date" with jQuery Datepicker where property minDate set to 0 (to show only future dates). I used a normal html <input type="text" to show the jQuery Datepicker and hide the <apex:input type="date" field.
Get the DatePicker
from DatePickerDialog
with getDatePicker()
. Set the max date to current date with setMaxDate()
:
mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
Requires API level 11.
You can call getDatePicker().setMaxDate(long) on your DatePickerDialog to set today as your maximum date. You can update the function with the same name from the snippet you posted.
Note:: DatePickerDialog is the object that I referenced in the Android Docs from the link I posted.
@Override protected Dialog onCreateDialog(int id) { Calendar c = Calendar.getInstance(); int cyear = c.get(Calendar.YEAR); int cmonth = c.get(Calendar.MONTH); int cday = c.get(Calendar.DAY_OF_MONTH); switch (id) { case DATE_DIALOG_ID: //start changes... DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday); dialog.getDatePicker().setMaxDate(System.currentTimeMillis()); return dialog; //end changes... } return null; }
Try this and give your feedback!!!
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