title: Android Room - Returning last 30 days (1 month) - java
body: <p>I am complete beginner in Android development and got stuck with a fairly simple problem (I guess ;) ).</p>
  
  <p>I am trying to retrieve records from SQLite (using Room) for last 30 days.</p>
  
  <p>This is my query which does not work - it does not return any records (from @Dao Class):</p>
  
  <pre><code> // getting fares for one day (custom-made query)
  @Query("SELECT * FROM fare WHERE createdDateDb &gt;=datetime('now', 'now', '-30 day')")
  public List&lt;Fare&gt; getFaresOneDay();
  </code></pre>
  
  <p>However, this simple query which retrieves all of the records without specified dates does work:</p>
  
  <pre><code> // getting all fare (via custom-made query)
  @Query("SELECT * FROM fare ORDER BY createdDateDb DESC")
  public List&lt;Fare&gt; getAllFares();
  </code></pre>
  
  <p>This is my DateTypeConverter class:</p>
  
  <pre><code>public class DateTypeConverter {
  
      @TypeConverter
      public long convertDateToLong(Date date) {
          return date.getTime();
      }
  
      @TypeConverter
      public Date convertLongToDate(long time) {
          return new Date(time);
      }
  
  }
  </code></pre>
  
  <p>This is how the value is being assigned to createdDateDb (before it is being inserted into DB):</p>
  
  <pre><code>fare.setCreatedDateDb(new Date());
  </code></pre>
  
  <p>This is my 'Entity' class:</p>
  
  <pre><code>@Entity(tableName = "fare")
  public class Fare {
      private String fareValue;
      private String typeOfJob;
  
      @PrimaryKey(autoGenerate = true) @NonNull
      private Integer jobId;
  
      // dates used for user display
      private String createdDate;
      private String createdTime;
  
      // date var used for comparisons - not to be displayed for the user
      private Date createdDateDb;
  }
  </code></pre>
  
  <p>and also setter and getter for createdDateDb</p>
  
  <pre><code>// #6 createdDateDb getter
  public Date getCreatedDateDb() {
      return createdDateDb;
  }
  
  // #6 createdDateDb setter
  public void setCreatedDateDb(Date createdDateDb) {this.createdDateDb = createdDateDb; }
  </code></pre>
  
  <p>I would really appreciate some hints how to approach it, as it feels like I'm getting nowhere.
  I have also tried the following:</p>
  
  <pre><code>SELECT * 
  FROM fare 
  WHERE createdDateDb BETWEEN datetime('now', 'start of month') AND datetime('now', 'localtime')
  </code></pre>
  
  <p>Unfortunately it did not work either.</p>
  
  <p>Thanks!</p>