scooby scooby - 1 year ago 128
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);

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

How to remove this bar?

Answer Source

Use strtotime while changing date format.

$date =   date("d/m/Y", strtotime("1988-12-04 00:00:00"));
 $teste = json_encode($date);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download