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?
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?
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)));
I had a similar problem, so I decided:
$data = implode('-', array_reverse(explode('/', $data)));
To use strtotime the way you put it, just replace "/" with "-".
$v_data= date('Y-m-d', strtotime(str_replace('/', '-', $data)))
That will work!