I am building a simple site that gathers some columns from an SQL Server and presenting them in an PHP Datatables site.
I have two different pages that gathers data from the SQL in the same way.
Here is working code:
$sql = "SELECT * FROM DATA_ORDER";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}
while( $row_get = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
      $options .= '<tr><td>' .$row_get['VAARREF']. '</td>'.
             '<td>' .$row_get['VAARREF']. '</td>'.
             '<td>' .$row_get['DOKNR']. '</td>'.
             '<td>' .$row_get['DATUM1']->format('d.m.Y'). '</td>'.
             '<td>' .$row_get['LOKALANM']. '</td>';
            }
    echo $options; 
sqlsrv_free_stmt( $stmt);
No problems there and the date is formatted as it should. DATUM1 column is date column in SQL.
Then I have this page with almost the exact same code:
 $sql = "SELECT * FROM DATA_PAYMENT2";
 $stmt = sqlsrv_query( $conn, $sql );
 if( $stmt === false) {
     die( print_r( sqlsrv_errors(), true) );
 }
 
 while( $row_get = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
       $options .= '<tr><td> Sen </td>'.
              '<td>' .$row_get['KOPPL_DOK1']. '</td>'.              
              '<td>' .$row_get['SENBETDAT']->format('d.m.Y'). '</td>'.
              '<td>' .$row_get['TOTALT']. '</td>'.
              '<td>' .$row_get['VALUTAKOD']. '</td>'.
              '<td>' .$row_get['DOKTYP']. '</td>'.
              '<td>' .$row_get['EU_KUND']. '</td>'.
              '<td>' .$row_get['ERORDER']. '</td>'.
              '<td>' .$row_get['NAMN']. '</td>'.
              '<td>' .$row_get['Payer_Address']. '</td>'.
              '<td>' .$row_get['SPRAAKKOD']. '</td>'.
              '<td>' .$row_get['ORGNR']. '</td>'.
              '<td>' .$row_get['ERREF']. '</td>'.
              '<td> Totalt </td>'.
              '<td>' .$row_get['DOKNR']. '</td>'.
              '<td>' .$row_get['LOKALANM']. '</td>';
             }
     echo $options;  
 sqlsrv_free_stmt( $stmt);
That recieves an error 500. If I comment out "SENBETDAT" row, then it all works. If I remove the format and the column is empty then it also works, but it wont work when there is data there with the format. I only get blank page. The column is also "date" in SQL and if I change this page to get data from the first table (DATA_ORDER) and get DATUM1, then it also works so I dont think there is any problem with the PHP code, but still I dont have any clue what the problem can be. I have tried to reconfigure the column to "date" but still no work.
Any suggestions?
 
     
    