material-daterange-picker icon indicating copy to clipboard operation
material-daterange-picker copied to clipboard

Make Selected date in TO tab always be greater than FROM selection

Open SirajShan opened this issue 8 years ago • 5 comments

If i select a future date in the From tab and i clicked on To tab. It is still showing current date as selected. The To tab value should be same or latter than The value selected in from tab.

SirajShan avatar Aug 28 '16 14:08 SirajShan

Any thought on this? any lead would be appreciated.

faisalmohd83 avatar Sep 06 '16 01:09 faisalmohd83

We need to have a function to set a data in each tab.

irinalomaka avatar Nov 08 '16 17:11 irinalomaka

@Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth, int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) { if(yearEnd < year){ ShowMessage("Please select current or future year"); }else if(monthOfYearEnd < monthOfYear){ ShowMessage("Please select current or future month"); }else if(dayOfMonthEnd < dayOfMonth){ ShowMessage("Please select current or future day"); }else { String date = "You picked the following date: From- "+dayOfMonth+"/"+(++monthOfYear)+"/"+year+" To "+dayOfMonthEnd+"/"+(++monthOfYearEnd)+"/"+yearEnd; ShowMessage(date); }

}

NB: Please watch the month pre-increments. i.e You should only increment once otherwise the month won't be correct

hawkraph avatar Aug 05 '19 05:08 hawkraph

I think @hawkraph is right. You can put validation once the User click OK button in the onDateSet method. Within this callback method, you can put any type of validation based on your business.

yasirtahir avatar Nov 20 '19 13:11 yasirtahir

@OverRide public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth, int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); try { Date fromDate = sdf.parse(dayOfMonth + "/" + monthOfYear + "/" + year); Date toDate = sdf.parse(dayOfMonthEnd + "/" + monthOfYearEnd + "/" + yearEnd); if (fromDate.after(toDate)) { Toast.makeText(this, "To Date must be after the From Date!", Toast.LENGTH_SHORT).show(); return; } } catch (ParseException e) { throw new RuntimeException(e); } }

nikulvaghani avatar Apr 25 '23 06:04 nikulvaghani