title: How to display total number of days between two dates using php
body: <p>I want to count the total number of days between two date.</p>
  
  <blockquote>
    <p>Note: I am not talking about the difference between two date</p>
  </blockquote>
  
  <p>I found lots of answer on google and Stack Overflow. I am sharing here</p>
  
  <pre><code>$now = time(); // or your date as well
  $your_date = strtotime("2018-06-01");
  $datediff = $now - $your_date;
  echo round($datediff / (60 * 60 * 24));
  </code></pre>
  
  <p>Output is 9</p>
  
  <pre><code>$now = strtotime("2018-06-09");
  $your_date = strtotime("2018-06-01"); 
  $datediff = $now - $your_date;
  echo $numberDays= round($datediff / (60 * 60 * 24));
  </code></pre>
  
  <p>Output is 8</p>
  
  <pre><code>$dStart = new DateTime('2018-06-01');
  $dEnd  = new DateTime('2018-06-09');
  $dDiff = $dStart-&gt;diff($dEnd);
  echo $dDiff-&gt;days;
  </code></pre>
  
  <p>Output is 8</p>
  
  <pre><code>$date1=date_create("2018-06-01");
  $date2=date_create("2018-06-09");
  $diff=date_diff($date1,$date2);
  echo $diff-&gt;format("%a");
  </code></pre>
  
  <p>Output is 8</p>
  
  <pre><code>$startTimeStamp = strtotime("2018-06-01");
  $endTimeStamp = strtotime("2018-06-09");
  $timeDiff = abs($endTimeStamp - $startTimeStamp);
  $numberDays = $timeDiff/86400;  // 86400 seconds in one day
  // and you might want to convert to integer
  echo $numberDays = intval($numberDays); 
  </code></pre>
  
  <p>Output is 8</p>
  
  <p>The correct answer for me is the first one 9 because it displays the total number of days from 1 to 9, not a difference.</p>
  
  <p>I just want to know how to get the count because I don't want to use the time() because it's taking the current date.</p>
  
  <p>For example: If I select the first date 2018-05-01 and my second date in 2018-05-31. So total days is 31, not 30.</p>
  
  <p>Example: 
  I am working on a project which is related to the working days and salary. So employee will select the date. for example. I am the employee and in the last month May, I select the date 2018-05-01 and 2018-05-31 so I have to display the total working days.So the according to the date I worked 31 days and using above code in the question I am getting 30 days.</p>
  
  <p>Hope you understand my issue. Would you help me out in this?</p>