title: Compare dates in MySQL using CASE
body: <p>I am stuck on trying to use some sql to figure out if a date is within 90, 60, or 30 days.  I think I am close but can't get it to work properly.  I have a column named boosterDate and it's a date in MySQL.  That column I want to check to see if it is within 90, 60, or 30 days from DATE(Now()) and then set the column boosterWithinDays to either 90, 60, or 30 days.  The table name is service.</p>
  
  <p>Here is where I am so far:</p>
  
  <pre><code>$sql = "SELECT
       CASE WHEN DATE(boosterDate) &lt; ADDDATE(DATE(NOW()),INTERVAL 90 DAY) THEN 90
       WHEN DATE(boosterDate) &lt; ADDDATE(DATE(NOW()),INTERVAL 60 DAY) THEN 60
       WHEN DATE(boosterDate) &lt; ADDDATE(DATE(NOW()),INTERVAL 30 DAY) THEN 30
       ELSE NULL END FROM service;";
  </code></pre>