Format hours and minutes presentation of variable read from SQL

3

I'm starting PHP. I want to display the hours and minutes stored in a field but when I read it what it presents is something like: 01:00:00.0000000 .

The SQL field is of type time (7) and the variable where I am reading is: $row["horas_assis"] . How do I only display the hours and minutes?

<table class="lista" align="center" width="100%" cellspacing="2" cellpadding="5">
    <tr>
        <th width="22%">Data</th>
        <th width="53%">Cliente</th>
        <th width="15%">Horas</th>
        <th></th>
    </tr>

    <?php
        $conn = ligarbd("assistec");
        $SQL = "SELECT * FROM assistencias WHERE id_tec=$id_tec";
        $result = odbc_exec($conn,$SQL);

        while($row = odbc_fetch_array( $result )){
    ?>
    <tr>
        <td><h7><?=$row["data"]?></h7></td>
        <td><?=$row["id_cli"]?></td>
        **<td><?=$row["horas_assis"]?></td>**
        <td>
            <a href="assistencias.php?id=<?=$row['id_tipo']?>&tipo=0"><img src="img/alterar_tec.png" alt="Editar"></a>
            <a href="assistencias.php?id=<?=$row['id_tipo']?>&tipo=1"><img src="img/apag_tec.png" alt="Apagar"></a>
        </td>
    </tr>
    <?php
        }
    odbc_close();
    ?>
</table>
    
asked by anonymous 08.03.2016 / 16:07

1 answer

2

You can use the date() function with strtotime() to format the time correctly, you can also do this directly through sql.

PHP

echo date('H:i:s', strtotime($row["horas_assis"]));

SQL

SELECT TIME_FORMAT('01:00:00.0000000', '%H:%i:%s')

Date () function parameters

Function Parameters TIME_FORMAT

    
08.03.2016 / 16:14