Problems with PHP date
-
I am using the following function to return the correct date of MySQL to the Brazilian format:
function FormatBR($data){ $date = date_create($data); $date = date_format($date, 'd/m/Y'); return $date; }
But the return is like this:
Does anyone know what's going on? Or if I'm doing the wrong way?
Grateful!
Where I raise JSON:
if (isset($_GET['id'])){ $id = trim($_GET['id']); $sql = "SELECT p.sequencia codigo, p.nome_completo nome, c.cpf cpf, c.rg rg, c.data_nascimento data, t.celular_1 celular_1, t.celular_2 celular_2, t.celular_3 celular_3, t.telefone_1 telefone_1, t.telefone_2 telefone_2, t.telefone_3 telefone_3, t.status status_telefone, e.email_1 email_1, e.email_2 email_2, e.status status_email, d.cep cep, d.rua endereco, d.numero numero, d.bairro bairro, d.complemento complemento, d.cidade cidade, d.estado estado, d.status status_end FROM pessoas p, clientes c, telefones t, emails e, enderecos d WHERE t.cod_pessoa = p.sequencia AND c.cod_pessoa = p.sequencia AND e.cod_pessoa = p.sequencia AND d.cod_pessoa = p.sequencia AND p.sequencia = $id"; $exec = mysqli_query($link, $sql); if ($exec){ while ($clientes = mysqli_fetch_assoc($exec)){ $convert = new convertData(); $data_nascimento = $convert->FormatBR($clientes['data']); $vetor[] = array('Codigo' => $clientes['codigo'], 'Nome' => $clientes['nome'], 'CPF' => $clientes['cpf'], 'RG' => $clientes['rg'], 'Data_Nacimento' => $data_nascimento, 'Celular_1' => $clientes['celular_1'], 'Celular_2' => $clientes['celular_2'], 'Celular_3' => $clientes['celular_3'], 'Telefone_1' => $clientes['telefone_1'], 'Telefone_2' => $clientes['telefone_2'], 'Telefone_3' => $clientes['telefone_3'], 'Status_telefone' => $clientes['status_telefone'], 'email_1' => $clientes['email_1'], 'email_2' => $clientes['email_2'], 'status_email' => $clientes['status_email'], 'cep' => $clientes['cep'], 'endereco' => $clientes['endereco'], 'numero' => $clientes['numero'], 'bairro' => $clientes['bairro'], 'complemento' => $clientes['complemento'], 'estado' => $clientes['estado'], 'status_end' => $clientes['status_end']); } } echo(json_encode($vetor));
-
It is returning the "interpreted" format by json, use json_decode to manipulate:
$data = ["Data_Nascimento" => "15/06/1995"]; $data = json_encode($data); var_dump($data); // Veja como fica como no exemplo que demonstrou $dataCorreta = json_decode($data); echo '<br>Data Formatada: '.$dataCorreta->Data_Nascimento;