Error converting data php

1
I'm getting the following date from a form: 26/09/2016 I need to convert it to: 2016-09-01 I'm using the following command: $v_data= date('Y-m-d', strtotime($data)); only giving the following return: 1970-01-01 , what would be wrong?

    
asked by anonymous 26.09.2016 / 20:49

3 answers

4

If you are receiving the date from mysql and want to convert to the Brazilian format use the following command:

$data = implode("/", array_reverse(explode("-", $data)));

This will create the mysql date in Brazilian format.

If you want to prepare the date in Brazilian format to insert into mysql use:

$data = implode("-", array_reverse(explode("/", $data)));
    
26.09.2016 / 20:59
2

I had a similar problem, so I decided:

$data = implode('-', array_reverse(explode('/', $data)));
    
26.09.2016 / 20:55
2

To use strtotime the way you put it, just replace "/" with "-".

$v_data= date('Y-m-d', strtotime(str_replace('/', '-', $data)))

That will work!

    
26.09.2016 / 20:58