Convert sql dates to Brazilian format in PHP

Asked

Viewed 102 times

-3

Good afternoon guys, I am not able to display and convert sql dates that were REGISTERED, I want to display in Brazilian format, someone can help me?

CODE

 <?php
$sql="";
require('conexaobd.php');

if (isset($_GET["pesquisa"])) {
$nome = $_GET["pesquisa"];
$sql = "SELECT numero_de_processo, paciente, data_de_entrada, convenio, tipo_de_internacao, data_saida FROM internacoes WHERE paciente LIKE '%$nome%' ORDER BY paciente ASC";
}else

$sql = "SELECT numero_de_processo, paciente, data_de_entrada, convenio, tipo_de_internacao, data_saida FROM internacoes ORDER BY paciente ASC";


$resultado = mysqli_query($link, $sql);

$inc = 0;

while ($cont = mysqli_fetch_array($resultado)) {
    echo "
       <tr> 

                <td>".$cont['paciente']."</td>   
                <td>".$cont['data_de_entrada']."</td> 
                <td>".$cont['convenio']."</td>
                <td>".$cont['tipo_de_internacao']."</td>
                <td>".$cont['data_saida']."</td>

                 <td> 
                 <a href='vizuinternacao.php?numero_de_processo=".$cont['numero_de_processo']."&paciente=".$cont['paciente']." target='new_blank'>
                <span class='role orange'> 
               <i class='fa fa-eye'></i>
                </span>
                </a>
                </td>

                <td> 
                 <a href='edit_internacao.php?numero_de_processo=".$cont['numero_de_processo']."&paciente=".$cont['paciente']." target='new_blank'>
                <span class='role user'> 
               <i class='fa fa-edit'></i>
                </span>
                </a>
                </td>
          </tr> 
    ";
}
?>   
    </tbody>
</table>

1 answer

0


I use a function for that:

converte_data($evento->dt_evento)

and the function:

function Converte_Data($data){
$data_nova = implode(preg_match("~\/~", $data) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $data) == 0 ? "-" : "/", $data)));
return $data_nova;}

The "Function" part, leaves inside the php block at the beginning of the page, the call changes your code this way:

<td>".converte_data($cont['data_de_entrada'])."</td> 

With this the function will be called passing the date as it comes from the database and returning the formatted date to our default.

Forehead...

  • Thanks for the answer... I am new to programming, the page is returning error, I do not know what to replace in this your code and where to put... If you can help me, I’d be very grateful.

  • Edited response to improve past information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.