Compare Start and End Date Android -


This question and an answer is already here

  • 11 answers

I have two functions in which This allows the user to set a specific date. This is the start date and end date. Now I need to compare these two variables because the start date should not be more than the end date. Here's some help my code is in android. Thank you

  private DatePickerDialog.OnDateSetListener mDateSetListener = to see new DatePickerDialog.OnDateSetListener () {public void onDateSet (DatePicker, int year, int monthOfYear, integer dayOfMonth) {year = year; Month = month only; Day = Day Ophthalmath; date. Set text ((month + 1) + "+" + "+ +" / "+ yr); }}; Private DatePickerDialog.OnDateSetListener mDateSetListener1 = new DatePickerDialog.OnDateSetListener () {public void onDateSet (DatePicker View1, integer YEAR1, integer monthOfYear1, integer dayOfMonth1) {year = YEAR1; Month = monthoffier1; Day = Day Offham 1; Dateand.set text ((month + 1) + "/" + + + "/" + yr); }};  

post text "itemprop =" text ">

Below is your code to compare two dates,

< Pre> SimpleDetermutation SDF = New SimpleDetermutation ("DD-MM-Yay"); String start = tvStartDate.getText (). ToString () Trim (); String enddate = TVand .get text (). ToString () Trim (); StartDate = startDate.substring (startDate.indexOf (":") + 1); EndDate = endDate.substring (endDate.indexOf (":") + 1); Start date = sdf.parse (startdate); Dat end date = sdf.parse (endDate); If (startDat.compareTo (endDat) & lt; = 0) {// OK} else {Toast.makeText (getApplicationContext (), "must be equal to at least start date or end date", Toast.LENGTH_SHORT). Show (); }

Comments