title: How to calculate the total working hour if login time is more then one in the table
body: <p>I am using CodeIgniter. I am calculating the total working hours in a day.</p>
  
  <p>So what I am doing is, When user login in the system It will insert the login time in the table and <code>is_active</code> status will <code>1</code>. Something like this</p>
  
  <p><a href="https://i.stack.imgur.com/GPECk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GPECk.png" alt="enter image description here"></a></p>
  
  <p>If the user log out then it will update the logout time and <code>is_active</code> status will <code>0</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/fb9J0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fb9J0.png" alt="enter image description here"></a></p>
  
  <p>If the same user login again then it will insert the new login time
  <a href="https://i.stack.imgur.com/DS5fZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DS5fZ.png" alt="enter image description here"></a></p>
  
  <p>Same process for logout.
  I can calculate the time between two dates but in my scenario, the user can log in multiple times.</p>
  
  <p>I am displaying the list of the record which is <code>is_active</code> status is 1.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public function get_current_login(){
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('tbl_employee');
          $this-&gt;db-&gt;join('tbl_current_login','tbl_current_login.emp_id=tbl_employee.id');
          //$this-&gt;db-&gt;where($where);
          $this-&gt;db-&gt;where('is_active',1);
          $query = $this-&gt;db-&gt;get();
          $result = $query-&gt;result(); 
            if($result)
            {
              return $result;
            }
            else 
            {
              return 0;
            }
      }
  </code></pre>
  
  <p>Above code will display the list of the user where <code>is_active</code> status is 1.(I haven't shared the view and controller code).</p>
  
  <p>Now I have to calculate the total working hours in a day.
  Is I am on the right path to insert and update the login and logout time? 
  Is it possible to calculate using MYSQL or I have to use PHP?</p>