Question: I am using the datepicker dialog and am trying to compare the current date with the date specified in the dialog.
if the date is before the current date I wish to display invalid date.

Both current date and date entered are in same format. but I am getting error. when printing in console both current date and entered date are coming the the same format

```
if(date1.before(currDate))
{
     Toast.makeText(getApplicationContext(), "Enter the valid Date", Toast.LENGTH_LONG).show();
}

```

result:

> 
> current date 5/7/2017
> 
> 
> picked date 5-7-2017
> 
> 
>

Answer: 
Try this

```
        String strCurrDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR);
        String strAnotherDate = "05/03/2017";
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

        try {
            Date currDate = formatter.parse(strCurrDate);
            Date anotherDate = formatter.parse(strAnotherDate);
            if (currDate.before(anotherDate)) {
                Toast.makeText(getApplicationContext(), "Enter the valid Date", Toast.LENGTH_LONG).show();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

```
you can directly deactivate past dates in datepicker by

```
datePicker.setMinDate(System.currentTimeMillis() - 1000);

```

You can compare time only by converting it in milliseconds

```
  Date setDateTime = input.parse(todayTime);
  calendar1.setTime(setDateTime);
  selectedTime=calendar1.getTimeInMillis();

  msTime = System.currentTimeMillis();//current time
//and compare msTime and setsetDateTime 
  if (selectedTime>msTime){
//your logic
}

```

or you can direct compare date by formating date format in digits only like 
for 5-7-2017 is 572017 and compare it to selected date in same format