I have the following line
echo date('Y-m-d', strtotime("28/09/2016")); // 1970-01-01
How do I get back 2016-09-28? If the day is less than 12, it returns true ...
I have the following line
echo date('Y-m-d', strtotime("28/09/2016")); // 1970-01-01
How do I get back 2016-09-28? If the day is less than 12, it returns true ...
You need to pass as a parameter to strtotime
a string with separator using -
(hyphen) for example;
$date = str_replace("/", "-", "28/09/2016");
echo date("Y-m-d", strtotime($date));
You can do this using the DateTime
object of PHP:
$formato = 'd/m/Y'; // define o formato de entrada para dd/mm/yyyy
$data = DateTime::createFromFormat($formato, "28/09/2016"); // define data desejada
echo $data->format('Y-m-d'); // formata a saída
Read more about the supported formats in PHP - DATE