1

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?

5
  • 3
    read the docs on date(), noting the second argument Commented Aug 24, 2016 at 18:18
  • Second argument of date is a timestamp, and you have a string. Commented Aug 24, 2016 at 18:18
  • See: Convert one date format into another in PHP Commented Aug 24, 2016 at 18:19
  • Use DateTime class. Commented Aug 24, 2016 at 18:19
  • Why do you think this is a problem with json_encode()? What do you see if you var_dump($date)? Commented Aug 24, 2016 at 18:33

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.