title: SQLite-net-pcl Comparing Dates
body: <p>As stated in the question I am attempting to do a date comparison for tasks that are done within a specific date range.</p>
  <p>My model has a boolean called &quot;Done&quot; and a string that stores dates of completion called &quot;DatesCompleted&quot;</p>
  <p>I currently have a query on that shows me all Done items limited to 25 and it works just fine:</p>
  <pre><code>return db.QueryAsync&lt;Tasks&gt;(&quot;SELECT * FROM [Tasks] WHERE [Done] = 1 LIMIT 25&quot;);
  </code></pre>
  <p>How can I get only dates completed that are 7 days prior to today? This is kind of sudo code how I'd expect to get the solution but I don't know how to write it out in SQLite-net-pcl,</p>
  <pre><code>return db.QueryAsync&lt;Tasks&gt;(&quot;SELECT * FROM [Tasks] WHERE [Done] = 1 AND [DatesCompleted] &gt;= (DateTime.Now - new TimeSpan(7,0,0,0))` LIMIT 25&quot;);
  </code></pre>
  <p>Edit:
  After attempting the first solution I am having no luck, all items regardless of completion time appear to show up. I tried this:</p>
  <pre><code> foreach(var ii in TaskListDoneSource)
                  {
                      System.Diagnostics.Debug.WriteLine(ii.Name + &quot; completed on : &quot; + ii.DateCompleted + &quot;  compared against &quot; + (DateTime.Now-new TimeSpan(7,0,0,0)).ToString());
                      if (ii.DateCompleted &gt; (DateTime.Now - new TimeSpan(7, 0, 0, 0)))
                          System.Diagnostics.Debug.WriteLine(&quot;The date completed has not quite hit 7 days&quot;);
  
                  }
  </code></pre>
  <p>The IF statement shows me that it is working when I am within 7 days but outside obviously no IF statement call. So that tells me I'm doing something wrong with the query recommended in first answer:</p>
  <blockquote>
  <p>SELECT *  FROM [Tasks]  WHERE [Done] = 1 AND [DateCompleted] &gt;=
  datetime('now', '-7 day')</p>
  </blockquote>
  <p>EDIT 2: I got it working with that query provided. Only thing that was off was off was having the DateCompleted as a DateTime instead of a string that was formatted properly in my model. (<a href="https://www.sqlite.org/lang_datefunc.html" rel="nofollow noreferrer">https://www.sqlite.org/lang_datefunc.html</a>)</p>