title: How to calculate total hours and minutes in a week of an employee
body: <p>I' am Querying to get the date and time of a employee from the database. Then I' am calculating the total hours and minutes they work in a day. Currently I' am stuck at a point where I need to calculate the total hours an employee has worked in a week. Please help, how do I calculate the total hours and minutes an employee has worked in a week.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>&lt;?php
      $sql = "SELECT * FROM records WHERE records_status = 'finished' AND record_created &gt; DATE_SUB('2014-10-19', INTERVAL 7 DAY)";
      $query = $db-&gt;SELECT($sql);
  ?&gt;
  &lt;table width="39%" border="1"&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td style="padding: 8px;"&gt;&lt;strong&gt;Day&lt;/strong&gt;&lt;/td&gt;
        &lt;td style="padding: 8px;"&gt;&lt;strong&gt;Total Hours&lt;/strong&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php
              $tally = "";
              foreach( $db-&gt;FETCH_OBJECT() as $row ){
                  $record_sign_in = $row-&gt;record_sign_in;
                  $record_sign_out = $row-&gt;record_sign_out;
                  $record_created = $row-&gt;record_created;
                  $time1 = date("H:i", strtotime($record_sign_in) );
                  $time2 = date("H:i", strtotime($record_sign_out) );
                  $record_created = date("l", strtotime($record_created) );
                  $day = $record_created;
                  list($hours, $minutes) = explode(':', $time1);
                      $startTimestamp = mktime($hours, $minutes);
                  list($hours, $minutes) = explode(':', $time2);
                      $endTimestamp = mktime($hours, $minutes);
                  $seconds = $endTimestamp - $startTimestamp;
                  $minutes = ($seconds / 60) % 60;
                  $hours = floor($seconds / (60 * 60));
  
                  $tally = "What to do here?";
          ?&gt;
      &lt;tr&gt;
        &lt;td style="padding: 8px;"&gt;&lt;?php echo $day; ?&gt;&lt;/td&gt;
        &lt;td style="padding: 8px;"&gt;&lt;?php echo $hours; ?&gt; hrs &lt;?php echo $minutes; ?&gt; min&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php } ?&gt;
      &lt;tr&gt;
        &lt;td style="padding: 8px;"&gt;Total&lt;/td&gt;
        &lt;td style="padding: 8px;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>This is how the visual table looks like.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/9GYB9.png" alt="enter image description here"></p>