title: Laravel $q->where() between dates
body: <p>I am trying to get my cron to only get <code>Projects</code> that are due to recur/renew in the next 7 days to send out reminder emails. I've just found out my logic doesn't quite work.</p>
  
  <p>I currently have the query:</p>
  
  <pre><code>$projects = Project::where(function($q){
      $q-&gt;where('recur_at', '&gt;', date("Y-m-d H:i:s", time() - 604800));
      $q-&gt;where('status', '&lt;', 5);
      $q-&gt;where('recur_cancelled', '=', 0);
  });
  </code></pre>
  
  <p>However, I realized what I need to do is something like:</p>
  
  <p>Psudo SQL:</p>
  
  <pre><code>SELECT * FROM projects WHERE recur_at &gt; recur_at - '7 days' AND /* Other status + recurr_cancelled stuff) */
  </code></pre>
  
  <p>How would I do this in Laravel 4, and using the DATETIME datatype, I've only done this sort of thing using timestamps. </p>
  
  <p><strong>Update:</strong></p>
  
  <p>Managed to solve this after using the following code, Stackoverflow also helps when you can pull bits of code and look at them out of context.</p>
  
  <pre><code>$projects = Project::where(function($q){
      $q-&gt;where(DB::raw('recur_at BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()'));
      $q-&gt;where('status', '&lt;', 5);
      $q-&gt;where('recur_cancelled', '=', 0);
  });
  </code></pre>
  
  <p><strong>Updated Question:</strong> Is there better way to do this in Laravel/Eloquent?</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>The first resolution ended up not been right after further testing, I have now resolved and tested the following solution:</p>
  
  <pre><code>$projects = Project::where(function($q){
      $q-&gt;where('recur_at', '&lt;=', Carbon::now()-&gt;addWeek());
      $q-&gt;where('recur_at', '!=', "0000-00-00 00:00:00");
      $q-&gt;where('status', '&lt;', 5);
      $q-&gt;where('recur_cancelled', '=', 0);
  });
  </code></pre>