title: MYSQL/PHP how to minus 7 days from date?
body: <p>I am using a system that tells me how many days out of 7 days it has taken for a user to re-submit data in a form to the database. The below script measures how many days have past from the original start date / when the form was originally filled out to when it was completed.</p>
  <p>Basically, I am trying to echo 2 different measures, if the days that have past from the start date are less than 7, then it should echo out <code>(number of days) out of 7 past</code></p>
  <p>i.e. 1 day of 7 past or 4 days of 7 past</p>
  <p>and if it has gone over 7days, it should then say <code>(number of days) overdue</code>.
  The problem I am getting is that I am allowing my users 7 days to submit the form. Bearing this in mind, they are not overdue therefore until it has gone past the 7 days timeframe, therefore if a user takes 8 days to complete the form they should only be one day overdue, however my script currently says 8 days overdue, as it takes into consideration the earlier 7.</p>
  <p>Is there a way I can minus 7 days to show once a user goes over the 7 day time frame?</p>
  <pre><code>&lt;?php include 'config.php';
       $data = mysql_query(&quot;SELECT *, TIMESTAMPDIFF(DAY, date, CURDATE()) AS expire_date FROM supplier_session ORDER BY expire_date ASC&quot;) 
       or die(mysql_error()); 
  
       echo &quot;&lt;table class=\&quot;table\&quot; style=\&quot;width:995px;  font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
       font-size:11px;\&quot; &gt;
  
  &lt;tr&gt;
      &lt;td style=\&quot;width:100px;\&quot;&gt;ID:&lt;/td&gt;&lt;td&gt;Company Name:&lt;/td&gt;&lt;td&gt;Company Reg No:&lt;/td&gt;&lt;td&gt;Application Started:&lt;/td&gt;&lt;td style=\&quot;width:200px;\&quot;&gt;Application Duration:&lt;/td&gt;&lt;td style=\&quot;width:100px;\&quot;&gt;Date:&lt;/td&gt;&lt;td&gt;Status:&lt;/td&gt;&lt;/tr&gt;&quot;;
  
  
       while($row = mysql_fetch_array( $data )) { 
          $days = $row['expire_date'];
          $when = $days*0; 
          $str = $row['expire_date'];
          $str2 = substr($str, 0); // &quot;quick brown fox jumps over the lazy dog.&quot;
         if ($when &lt;= 31){
         echo &quot;&lt;tr&gt;&lt;td style=\&quot;width:100px;\&quot;&gt;&lt;p&gt;&quot;.$row['id'] . &quot;&lt;/p&gt;&lt;/td&gt;&quot;; 
         echo &quot;&lt;td style=\&quot;width:150px;\&quot;&gt;&lt;p&gt;&quot;.$row['company_name'] . &quot;&lt;/p&gt;&lt;/td&gt;&quot;; 
         echo &quot;&lt;td style=\&quot;width:150px;\&quot;&gt;&lt;p&gt;&quot;.$row['company_reg_number'] . &quot;&lt;/p&gt;&lt;/td&gt;&quot;;
         echo &quot;&lt;td&gt;&quot;; echo date('d/m/Y',strtotime($row['date'])); echo &quot;&lt;/td&gt;&quot;;
         
        
         if ($days &gt;= 8) {
              echo &quot;&lt;td style=\&quot;width:200px;\&quot;&gt;&lt;p&gt;{$str2} days overdue&lt;/td&gt;&quot;;
         }
         
          elseif ($when &lt;= 7){
              
          
               echo &quot;&lt;td style=\&quot;width:200px;\&quot;&gt;&lt;p&gt;{$str2} of 7 days past&lt;/td&gt;&quot;;
          }
          
          
  
            
          }
       
  
          echo &quot;&lt;tr&gt;&quot;;
        }
       
      
        echo &quot;&lt;/table&gt;&quot;; //Close the table in HTML
        
       
      ?&gt;
  </code></pre>