title: How can I calculate the number of working days between two dates
body: <p>We have a PHP based timesheet system that's been developed in house, and has evolved over the years, however one piece of information presented to the users is the number of working days remaining on each project.</p>
  
  <p>Currently, I simply take the difference between the current date and project end date, and divide by 7 and multiply by 5. This has sufficed for a long time and is mostly accurate enough for staff that work full time Monday to Friday. However, we now have a number of staff who work only the odd day a week.</p>
  
  <p>The timesheet system is aware of what days which staff work, this information is stored in a string in the user class, for a full time worker, the value would be <code>NNYYYYY</code> (meaning <code>ssMTWTF</code>).</p>
  
  <p>I could very easily make the result more accurate, by dividing the difference between the two dates by seven, and then multiplying by the number of days they work, but whilst making this change, I'm considering producing a much more accurate means of calculating the real value.</p>
  
  <p>The easiest way that springs to mind would be to just use a loop between the two dates, comparing the day of the week to the user's working pattern, adding one to a counter on days where the user works that day.</p>
  
  <p>Given that this calculation has to be performed on average about 30 times per page view due to the number of projects on the timesheet and projects can span 12 or 18 months at a time (that's a lot of looping for every page load), I'm wondering if there's a more efficient method of doing this in PHP?</p>