title: Android - SQLite - SELECT BETWEEN Date1 AND Date2
body: <p>Mac OS-X</p>
  
  <p>Android </p>
  
  <p>Eclipse with ADT</p>
  
  <p>SQLite</p>
  
  <p>I'm new to creating Android Apps and Ive researched this heavily but I'm getting nowhere. I need to query my SQLite database to return all the rows between 2 dates. What I have learnt from my research so far is that there is no DateTime column in Androids SQLite database and I have to save it as a text column. But I think the problem lies with trying to compare Strings but I can't figure out a way around it. Here is my code :</p>
  
  <pre><code>DB = currentContext.openOrCreateDatabase(DBName, 0, null);
  DB.execSQL("CREATE TABLE IF NOT EXISTS " + tableName + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Date VARCHAR(40), Hours INT(3));");
  </code></pre>
  
  <p>I am not getting any errors but I am not returning any results from my RawQuery. Here is my code:</p>
  
  <pre><code>Cursor c = newDB.rawQuery("select ID, Date, Hours from " + tableName + " where Date BETWEEN '" + date1 + " 00:00:00' AND '" + date2 + " 99:99:99'", null);
  
  if (c != null ) {
    Log.d(TAG, "date1: "+date1);
    Log.d(TAG, "date2: "+date2);
    if  (c.moveToFirst()) {
       do {
          int id = c.getInt(c.getColumnIndex("ID"));
          String date1 = c.getString(c.getColumnIndex("Date"));
          int hours1 = c.getInt(c.getColumnIndex("Hours"));
          results.add(+ id + "    Date: " + date1 + "    Hours: " + hours1);
       }
           while (c.moveToNext());
        }
  }
  </code></pre>
  
  <p>I have also tried the following statement but they do not yield results either:</p>
  
  <pre><code>Cursor c = newDB.rawQuery("select ID, Date, Hours from " + tableName + " where Date BETWEEN " + Date(date1) + " AND " + Date(date2) + "", null);
  </code></pre>
  
  <p>I got this statement from other StackOverflow answers but I cannot find any documentation on the date() method. Im not sure whether it is obsolete now but I get error saying "Date(String) method is undefined for the type (classname)" and I have tried importing some JAVA Libraries.</p>
  
  <p>Does anyone know the correct way to create a rawData() query that will get the rows between selected dates??</p>
  
  <p>Further info, these are my INSERT statements and the date format that goes into the database:</p>
  
  <pre><code>newDB.execSQL("INSERT INTO " + tableName + " (Date, Hours) Values ('" + ph_date + "'," + hours + ");");
  String date1 = "12/1/13"
  String date2 = "25/1/13"
  </code></pre>