title: Storing and then comparing a date (in String format) with current date as a condition in a SQLite query
body: <p>I am creating an app in which i add a due date for my clients in SQLite database, and then want to retrieve those clients whose due dates arrive. Mean that I want to use a condition for a query where due date is &lt; current date, and then fetch the data in a RecyclerView. I am also saving the date in the database as string in yyyy-MM-dd format, using SimpleDateFormat and Calendar classes.  But the problem is that nothing is being shown in my RecyclerView.</p>
  
  <p>This is the function I use to fetch that data from the database, where CLDUE is the due date column:</p>
  
  <pre><code> public static Cursor getPayDueData(String act)
          {   act = "Active";
              SQLiteDatabase db = sqh.getReadableDatabase();
              Calendar c = Calendar.getInstance();
              SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
              String CurrentDate = df.format(c.getTime());
              String[] payData = {CLID,CLNM,CLDUE,CLFEE};
              return  db.query(TBL_CLIENTS,payData," CLDUE &lt;= " + CurrentDate + " AND CLACT = ? ",new String[]{act},null,null,null);
          }
  </code></pre>
  
  <p>and this is the Activity where the data is to be fetched:</p>
  
  <pre><code>public class Payments extends AppCompatActivity {
  
  ArrayList&lt;PayRecInfo&gt; payRecInfoArrayList;
  RecyclerView rc;
  PayRecyclerAdapter payRecyclerAdapter;
  MyDb myDb;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_payments);
      myDb = new MyDb(this);
      rc = (RecyclerView)findViewById(R.id.recyclerView2);
      rc.setLayoutManager(new LinearLayoutManager(this));
      payRecInfoArrayList = new ArrayList&lt;&gt;();
      payRecyclerAdapter = new PayRecyclerAdapter(this, payRecInfoArrayList);
      rc.setAdapter(payRecyclerAdapter);
  
      retrievePayDueCl();
  }
  
  public void retrievePayDueCl()
  {
          payRecInfoArrayList.clear();
          Cursor cursor = MyDb.TblClients.getPayDueData("Active");
          if(cursor != null)
          {
              cursor.moveToPosition(-1);
              while(cursor.moveToNext())
              {
                  try{
                     int id2 = cursor.getColumnIndex(CLID);
                     int nm2 = cursor.getColumnIndex(CLNM);
                     int du2 = cursor.getColumnIndex(CLDUE);
                     int fee2 = cursor.getColumnIndex(CLFEE);
                     String PayID = cursor.getString(id2);
                     String PayName = cursor.getString(nm2);
                     String PayDue = cursor.getString(du2);
                     String PayFee = cursor.getString(fee2);
  
                     PayRecInfo payRecInfo = new PayRecInfo(PayID, PayName, PayDue, PayFee);
                     payRecInfoArrayList.add(payRecInfo);
                     payRecyclerAdapter.notifyDataSetChanged();
                     rc.setAdapter(payRecyclerAdapter);
                   }catch (Exception e){e.printStackTrace();}
              }
          }
  }
  </code></pre>
  
  <p>and this is my adapter class for RecyclerView:</p>
  
  <pre><code>class PayRecyclerAdapter extends RecyclerView.Adapter&lt;PayRecyclerAdapter.MyHolder&gt; {
  
  Context ctx;
  ArrayList&lt;PayRecInfo&gt; payRecInfo;
  
  PayRecyclerAdapter(Context ctx, ArrayList&lt;PayRecInfo&gt; payRecInfo){
      this.ctx = ctx;
      this.payRecInfo = payRecInfo;
  }
  
  
  @Override
  public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view  = LayoutInflater.from(ctx).inflate(R.layout.custom_row_payments,parent,false);
      return new MyHolder(view);
  }
  
  @Override
  public void onBindViewHolder(MyHolder holder, int position) {
      try
      {
        if(payRecInfo != null) {
        holder.PayId.setText(payRecInfo.get(position).getId2());
        holder.PayName.setText(payRecInfo.get(position).getName2());
        holder.PayDue.setText(payRecInfo.get(position).getDue2());
        holder.PayFee.setText(payRecInfo.get(position).getFee2());
        }
      }
      catch(Exception e){e.printStackTrace();}
  }
  
  @Override
  public int getItemCount() {
      if(payRecInfo != null)
      return payRecInfo.size();
      else return 0;
  }
  
  class MyHolder extends RecyclerView.ViewHolder {
      TextView PayId, PayName, PayDue, PayFee;
      MyHolder(View itemView) {
          super(itemView);
          PayId = (TextView)itemView.findViewById(R.id.PayId);
          PayName = (TextView)itemView.findViewById(R.id.PayNameTxt);
          PayDue = (TextView)itemView.findViewById(R.id.PayDueDateTxt);
          PayFee = (TextView)itemView.findViewById(R.id.PayFeeTxt);
      }
  }
  }
  </code></pre>
  
  <p>And here is how i insert the dates to db:
          public static long insertData(RecClNames recClNames)
       {  try{
                  SQLiteDatabase db =sqh.getWritableDatabase();</p>
  
  <pre><code>            ContentValues cv = new ContentValues();
  
              cv.put(CLNM,recClNames.getName());
              cv.put(CLMNO,recClNames.getPhone());
              cv.put(CLHT,recClNames.getHeight());
              cv.put(CLAGE,recClNames.getAge());
              cv.put(CLWT,recClNames.getWeight());
              cv.put(CLEML,recClNames.getEmail());
              cv.put(CLADD,recClNames.getAddress());
              cv.put(CLFEE,recClNames.getFee());
              cv.put(CLDATE,recClNames.getDate());
              cv.put(CLDUE,recClNames.getDue());
              cv.put(CLDUR,recClNames.getDuration());
              cv.put(CLACT,recClNames.getActive());
              cv.put(CLSPCS,recClNames.getSpCase());
  
              return db.insert(TBL_CLIENTS,CLID,cv);}
          catch (Exception e){e.printStackTrace();}
              return 0; }
  </code></pre>
  
  <p>recClNames is the arraylist object. Here the registration date is the current date and the due date is the date after 1 month of it. But the due date is up, its not showing in the RecyclerView</p>
  
  <p>I guess the problem is the condition of the SQLite query,  but however, i cannot solve this problem.<br>
  Please help.</p>