Is it possible to pass this date "January 12, 2017" to the US standard (Y-m-d)?
Any examples?
Thank you.
Is it possible to pass this date "January 12, 2017" to the US standard (Y-m-d)?
Any examples?
Thank you.
Using the date_create_from_format function, you can format the date as you wish but first you should make some changes:
$string = "12 de Dezembro de 2017";
$string = preg_replace('/( de ){1,2}/', ' ', $string);
$month = [
'Janeiro' => 'January',
'Fevereiro' => 'February',
'Marco' => 'March',
'Abril' => 'April',
'Maio' => 'May',
'Junho' => 'June',
'Julho' => 'July',
'Agosto' => 'August',
'Novembro' => 'November',
'Setembro' => 'September',
'Outubro' => 'October',
'Dezembro' => 'December'
];
$string = str_replace(array_keys($month), array_values($month), $string);
$dr= date_create_from_format('d M Y', $string);
echo $dr->format('Y-m-d');
date('Y-m-d', strtodate($string));