title: Android - Compare two dates
body: <p>I want to compare two dates in my application</p>
  
  <p>The first date will be todays date
  The second will come from a database</p>
  
  <p>To save the second date my code is as follows; (Used tomorrows date to keep it simple)</p>
  
  <pre><code> Calendar calendar = Calendar.getInstance();
   calendar.add(Calendar.DAY_OF_YEAR, 1);
   Date tomorrow = calendar.getTime();
   DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
  
   String tomorrowAsString = dateFormat.format(tomorrow);
  </code></pre>
  
  <p>So <code>tomorrowAsString (10-Oct-2015)</code> is stored in a table in my database</p>
  
  <p>In another form I'm retrieving that date and putting it into a String</p>
  
  <pre><code>String steepingDate = (c.getString(3));
  </code></pre>
  
  <p>I imagine that I'll need to convert that string into a date format and then use the following to get todays date;</p>
  
  <pre><code>Calendar calendar = Calendar.getInstance();
  Date today = calendar.getTime();
  DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
  
  String todayAsString = dateFormat.format(today);
  </code></pre>
  
  <p>Here is where I'm getting stuck as I'm not sure how to turn the <code>steepingDate</code> into a <code>Date</code> and then what is the actual way of comparing the strings, I've tried looking online but there's so many different ways that I've tried and none so far have worked. I want to know which one of the two is grater</p>
  
  <p>EDIT:</p>
  
  <p>I've combined some of the answers and come up with the following;</p>
  
  <pre><code>do {
        String steepingDate = (c.getString(3));
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        Date steepingdate = formatter.parse(steepingDate);
  
        Calendar calendar = Calendar.getInstance();
        Date today = calendar.getTime();
  
        if(today.compareTo(steepingdate)&gt;0)
        {
           CompleteSteeping.add(c.getString(1));
        }
        i += 1;
     }while (c.moveToNext());
  </code></pre>
  
  <p>However on;</p>
  
  <pre><code>SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
  Date steepingdate = formatter.parse(steepingDate);
  </code></pre>
  
  <p>I'm getting an error stating </p>
  
  <p>'Unparseable date: "java.util.GregorianCalender[time=1444461352665,areFieldsSet=true,Ienient=true\zone=GMT,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2015,MONTH=9,WEEK_OF_YEAR=41,WEEK_OF_MONTH=2,DAY_OF_MONTH=10,DAY_OF_YEAR=283,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=2,AM_PM=0,HOUR=7,HOUR_OF_DAY=7,MINUTE=15,SECOND=52,MILLISECOND=665,ZONE_OFFSET=0DST_OFFSET=0]" (at offset 0)</p>