1

I have two dates i.e Startdate and Enddate.I am using DatePickerDialog. Suppose my Startdate is 1-3-2014 then I want to restrict Enddate going to previous date of Startdate.

Sandeep
  • 197
  • 1
  • 8

1 Answers1

3

It's very simple just use it like this.

if (DueDate.before(AssignDate))
{
 AlertDialog.Builder alertDialogBuilderDate = new AlertDialog.Builder(
                        Assignment_Create_Ext_DB.this);
                alertDialogBuilderDate.setTitle("Date assigning issue");
                alertDialogBuilderDate
                        .setMessage(
                                "Due date can not be equal or less then the Assign date")
                        .setCancelable(false)
                        .setPositiveButton("Ok",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                alertDialogBuilderDate.show();
}
else
{
  // use your coding
}

or same like this also you can check

if (DueDate.after(AssignDate))
{

  // use your coding
}
else
{
  AlertDialog.Builder alertDialogBuilderDate = new AlertDialog.Builder(
                        Assignment_Create_Ext_DB.this);
                alertDialogBuilderDate.setTitle("Date assigning issue");
                alertDialogBuilderDate
                        .setMessage(
                                "Due date can not be equal or less then the Assign date")
                        .setCancelable(false)
                        .setPositiveButton("Ok",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                alertDialogBuilderDate.show();
}

Difference is just before and after keyword.

Here duedate and assigndate both are your Calendar variable.

InnocentKiller
  • 5,234
  • 7
  • 36
  • 84