title: Calendar query sorted by date and time
body: <p>I am trying to return a query of Calendar events sorted by date and time so that I can iterate through them. I have queried it like so:</p>
  
  <pre><code>private Cursor mCursor = null;
  private static final String[] COLS = new String[]{CalendarContract.Events.TITLE, CalendarContract.Events.DTSTART, CalendarContract.Events.AVAILABILITY};
  mCursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, COLS, null, null, null);
  mCursor.moveToLast();
  </code></pre>
  
  <p>This works great except it seems to return the calendar events based on when it was created and not by date and time. For example, if I create a new event for December 25, 2012, it will show up as the last result. </p>
  
  <p>My end goal is that I would like to find the first event that starts before the current time. For example, if it is currently 8:00am, I want to find the first event that starts before 8:00am. I want to then check the duration of that event to see if it is a currently ongoing event.</p>
  
  <p>Is there an easy way to return a query sorted by date and time or will I have to implement a sort after the results are queried? Better yet, is there a simple way to find the first event before the current time?</p>