How to make a date in full on common date?

4

I get a string with a date, and unfortunately there's no way to change it, in the format:

  

September 1, 2015

And make it into:

  

01/09/2015

The only way I found to do this would be by breaking the string and forming an array, and checking the necessary parts. But is there any other way?

I know there is no way to use strtotime and strftime .

    
asked by anonymous 01.09.2015 / 17:57

2 answers

4

One way to solve this is to replace the month me and Portuguese by English in an array with the help of str_replace() .

<?php

$en = ['','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
$pt = [' de ', 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro']; 

$data = '1 de setembro de 2015';
$data = str_replace($pt, $en, $data);
echo date('Y-m-d', strtotime($data));
    
01.09.2015 / 19:16
0

I would do it as follows:

function arruma_data($data){
    $arr_mes = array("Setembro"=>"09","Outubro"=>"10","Novembro"=>"11");
    $arr_data = explode(" de ",data)
    $datafim = str_pad($arr_data [0],2,"0",STR_PAD_LEFT)."/".$arr_mes[$arr_data[1]]."/". $arr_data[2];
    return $datafim;
}

echo $this->arrumada_data("1 de setembro de 2015");
    
24.10.2018 / 22:39