title: Subtract dates to get the number of days
body: <p>I am trying to write a php code which will be able to subtract two dates and get the number of days between the two dates. The code I came up with is given below</p>
  
  <pre><code>&lt;?php
  $c_date = date("Y-m-d");
  //Subtracting two dates.
  $date1 = new DateTime($d_date); //$d_date gets its value from database which i havent shown here
  $date2 = new DateTime($c_date);
  $interval = $date1-&gt;diff($date2);
  echo "difference " . $interval-&gt;y . " years, " . $interval-&gt;m." months, ".$interval-&gt;d." days ";
  ?&gt;
  </code></pre>
  
  <p>Now the above code works but I am not able to use it to suit my needs. I need to be able to find out if the delivery date ($d_date) is within 5 days from the current date and return value 1 if that is that case. </p>
  
  <p>So if <code>$c_date = "2013-09-24"</code> and <code>$d_date = "2013-09-30"</code> then I will be returning 1. 
  But the trouble is when say the delivery date is "2013-09-19" the delivery date has long past and I should be returning 0, but with the current code the difference in day would still be 5 and so i will be returning 1 which is wrong. </p>
  
  <p>Have any ideas as to how to overcome this?</p>