title: To Count users sick, then take that away form given limits based on years of service
body: <p>I am very new to PHP and even more new to CakePHP, which is what my code is writen for but I think my problem is with some of my standard PHP code.</p>
  
  <p>OK, now this code is mostly working but it seems to give me a wrong result when my selected user takes more than one day of at the same time!</p>
  
  <p>OK, so what it is meant to do is to get the years of service for the selected user, it does that OK (i think, no problems at lest). Then from years of service I set sick entitlement, full days and then half days based on years of service. </p>
  
  <p>Once I have done that the code should get the selected users taken sick and with that take off the what they have taken with the entitlement, 1st the full, then when that is empty take it off the half. But like I said when the user takes more than one day off in a row, it still only takes off one day? </p>
  
  <p>It might be where I start my foreach loop and do the count, not sure if that is right? </p>
  
  <p>Please help??</p>
  
  <pre><code> function sickDay($id = null) {
      if($this-&gt;CURRENT_USER['User']['role_id'] &gt; 3) { //directors and admins
      /*if(empty($this-&gt;data) || !isset($this-&gt;data['Holiday']['id'])) {
  
      } else {*/
          //Caculate if it's a full pay, half pay or nothing
          //$data = $this-&gt;data['Holiday'];
  
          //Get Holidaytypes
          $types = $this-&gt;Holiday-&gt;find(
              'all',
              array(
                  'conditions' =&gt; array(
                      'Holiday.holidaystype_id' =&gt; 3,
                      'Holiday.user_id' =&gt; $id
                  )
              )
          );
  
          //Get starting date
          $contracts = $this-&gt;Holiday-&gt;User-&gt;Contract-&gt;find(
              'all',
              array(
                  'conditions' =&gt; array(
                      'Contract.user_id' =&gt; $id //$data['user_id']
                  ),
                  'order' =&gt; array(
                      'Contract.startson' =&gt; 'ASC'
                  )
              )
          );
          //Get How Many sick days
          foreach ($types as $key =&gt; $value) {
  
              $typesDataEnds =  strftime ("%u-%d-%Y", $types[$key]['Holiday']['endson']);
              $typesDataStarts = strftime ("%u-%d-%Y", $types[$key]['Holiday']['startson']);
  
              $SickTotal = count($typesDataEnds - $typesDataStarts);  
              //echo $SickTotal;
  
          //Get Contract Start &amp; End Dates
          $start = array_shift($contracts);
          $end = array_pop($contracts);
  
          $endDate = $end['Contract']['endson'];
          $startDate = $start['Contract']['startson'];
  
          if (empty($endDate)) {
                  $endDate = time('now');
          }
          if (!empty($startDate)) {
              $SortEnd = strftime("%Y", $endDate);
              $SortStart = strftime("%Y", $startDate);
              $YearsService = $SortEnd - $SortStart;
  
              if ($YearsService &lt;= 1) {
                      $SetFullEntitlement = 5;
                      $SetHalfEntitlement = 5;
                      //echo 'one year';
              } elseif ($YearsService &lt;= 2) {
                      $SetFullEntitlement = 10;
                      $SetHalfEntitlement = 10;
                      //echo 'two years';
              } elseif ($YearsService &lt;= 5) {
                      $SetFullEntitlement = 20;
                      $SetHalfEntitlement = 20;
                      //echo 'up to five years';
              } elseif ($YearsService &gt;= 6) {
                      $SetFullEntitlement = 30;
                      $SetHalfEntitlement = 30;
                      //echo 'five years or more';
              } else {
                      $SetFullEntitlement = 0;
                      $SetHalfEntitlement = 0;
                      //echo 'no sick pay';
              }
          } else {
              $YearsService = 0;
              //echo 'Sorry No Start Date For You Found!';
          }
  
          while ($SickTotal &gt; 0) {
              if ($SetFullEntitlement != 0) {
                  $SetFullEntitlement--;
              } elseif ($SetHalfEntitlement != 0) {
                  $SetHalfEntitlement--;
              }
              $SickTotal--;
          }
  
          echo 'FullPay:';
          echo $SetFullEntitlement;
          echo '&lt;br/&gt;&lt;br/&gt;Halfpay:';
          echo $SetHalfEntitlement;
  
          }
  
          //debug($SickTotal);
          die();  
          //$this-&gt;render('/artists/holidayslist');
      //} //End For if empty check
   } // End for if CURRENT_USER
  } //End of Function
  </code></pre>
  
  <hr>
  
  <p>Update</p>
  
  <p>I understand what you have said and yes, I do now know %u was wrong to use for what I need it to do. Now I have done what you said but I get back 0 for a selected user, which I know should have two?</p>
  
  <pre><code>foreach ($types as $key =&gt; $value) {
  
      $typesDataEnds =  strtotime($types[$key]['Holiday']['endson']);
      $typesDataStarts = strtotime($types[$key]['Holiday']['startson']);
  
      //$typesDataEnds =  strftime ("%Y-%m-%d", $types[$key]['Holiday']['endson']);
      //$typesDataStarts = strftime ("%Y-%m-%d", $types[$key]['Holiday']['startson']);
  
      $sickTotal = floor(($typesDataEnds - $typesDataStarts) / 86400);
  
      echo 'testing: ';
      debug($sickTotal);
  
      die();
  
   does more.....
  
   } //end
  </code></pre>
  
  <p>Have I done something wrong?</p>
  
  <p>Many Thanks for the help</p>
  
  <p>Glenn.</p>