title: how to substrac two fields from the same column in sql server using php calculation
body: <p>i have SQL server database , and I'm using php to connect to it and using queries.
  i've read two records from the database for one employee. and i need them to calculate the works hours to the employee. but i couldn't figure how to select to fields from the same column to the same employee. as in the picture:</p>
  
  <p>E003   2014-03-17    08:10:12    2221</p>
  
  <p>E003   2014-03-17    10:05:02    2222</p>
  
  <p>E003   2014-03-17    12:15:20    2221</p>
  
  <p>E003   2014-03-17    15:03:30    2222</p>
  
  <p>the 2221 is the entring door, and the 2222 is the exit door. i want to select the time from the 2222 and substract them to have the works hours for the employee. can you help me with that pleas, this is my code:</p>
  
  <pre><code>&lt;?php
  
  $host = "servername\instancename";
  $connectionInfo = array( "Database"=&gt;"AccessCard", "UID"=&gt;"", "PWD"=&gt;"");
  $conn = sqlsrv_connect( $host, $connectionInfo);
  if( $conn === false ) {
      die( print_r( sqlsrv_errors(), true));
  }
  echo "&lt;/br&gt;"; 
  
  /**********************************************/
  $FRISTsql = "SELECT [EmpID],[DATE],[TIME],[OBJECT] FROM [AccessCard].[dbo].[TimeAtt] WHERE [EmpID]='E003'";
  $Fstmt = sqlsrv_query( $conn, $FRISTsql );
  if( $Fstmt === false) {
      die( print_r( sqlsrv_errors(), true) );
  }
  while( $Frow = sqlsrv_fetch_array( $Fstmt, SQLSRV_FETCH_ASSOC) ) {
  
        $R1 = $Frow['EmpID'];
        $R2 = $Frow['DATE']-&gt;format('Y-m-d');
        $R3 = $Frow['TIME']-&gt;format('H:i:s');
        $R4 = $Frow['OBJECT'];
  
       ECHO $R1." &amp;nbsp&amp;nbsp";
       ECHO $R2." &amp;nbsp&amp;nbsp&amp;nbsp";
       ECHO $R3." &amp;nbsp&amp;nbsp&amp;nbsp";
       ECHO $R4."&lt;/BR&gt; ";
  
  }
  sqlsrv_free_stmt( $Fstmt);
  </code></pre>