Error converting php data

Asked

Viewed 434 times

1

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

3 answers

4


If you are receiving the mysql date and want to convert to 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 in mysql use:

$data = implode("-", array_reverse(explode("/", $data)));
  • Used: $data = implode("-",array_reverse(explodes("/",$data)); Thanks for the help.

  • How would the same situation be for currency ?

  • $numero = 1234.56; echo number_format($numero, 2, ',', '.');

  • In fact and my sum going wrong, ...

  • The following is the question: http://answall.com/questions/155079/erro-ao-somar-2-valores-em-php

2

I had similar problem, I solved so:

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

2

to use strtotime the way you put it, simply replace "/" with "-".

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

that will work!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.