End-date greater than start-date validation android
SimpleDateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd");
public static boolean checkDates("2012-07-12", "2012-06-12)" {
boolean b = false;
try {
if(dfDate.parse(d1).before(dfDate.parse(d2)))
{
b = true;//If start date is before end date
}
else if(dfDate.parse(d1).equals(dfDate.parse(d2)))
{
b = true;//If two dates are equal
}
else
{
b = false; //If start date is after the end date
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
Try this function.
public static boolean isDateAfter(String startDate,String endDate)
{
try
{
String myFormatString = "yyyy-M-dd"; // for example
SimpleDateFormat df = new SimpleDateFormat(myFormatString);
Date date1 = df.parse(endDate));
Date startingDate = df.parse(startDate);
if (date1.after(startingDate))
return true;
else
return false;
}
catch (Exception e)
{
return false;
}
}
It return true if enddate is after start date.