change the format to display of a date field in mysql with php

0

How can I change the format that a date is displayed:

To show the dates of a table, they are shown as follows:

  • 2016-06-28
  • 2016-06-29
  • 2016-07-01
  • 2016-07-03

And I wanted to change that sample format for one like this:

  • 2016, 06, 28
  • 2016, 06, 29
  • 2016, 07, 01
  • 2016, 07, 03

This is the code with which I am showing my dates:

<?php 
include 'conexion.php';
$sql = "SELECT * FROM venta";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["fecha_emision"]."<br>";

}
} else {
    echo "0 results";
}
$conn->close();
?>

Any way to do it?

    
asked by Raphael 03.07.2016 в 20:27
source

2 answers

2

You would only have to format the date

date("y,m,d", strtotime($row["fecha_emision"])); 

that would generate the date format in which you require it

    
answered by 03.07.2016 / 20:33
source
1

Although it's easier than it has told you Miguel Osorio , I usually have it with a php query .

function cambiaf_a_normal($fecha,$caracter){ 
   ereg( "([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})", $fecha, $mifecha); 
   $lafecha=$mifecha[1].$caracter.$mifecha[2].$caracter.$mifecha[3]; 
   return $lafecha; 
}
    
answered by 03.07.2016 в 23:41