scooby scooby - 3 months ago 16
JSON Question

php json_encode convert wrong date

I need to send data in json format, but to convert the date it loses the original formatting:

$date = date("d/m/Y", "1988-12-04 00:00:00");
$teste = json_encode($date);
var_dump($teste);exit;


I need this format: 04/12/1988, but print: string '"01/01/1970"' (length=14)

How to remove this bar?

Answer

Use strtotime while changing date format.

$date =   date("d/m/Y", strtotime("1988-12-04 00:00:00"));
 $teste = json_encode($date);
 var_dump($teste);exit;