Problem with date Laravel

2

My problem is with date conversion, see:

echo date('Y-m-d', strtotime(Input::get('data_evento')));

echo of Input::get('data_evento') : 14/02/2014

echo of date('Y-m-d', strtotime(Input::get('data_evento'))) : 1969-12-31

I really do not know what's going on.

    
asked by anonymous 14.02.2014 / 18:15

2 answers

4

With pure php in version 5.3 utlize createFromFormat from < DateTime to convert the format from dd/mm/Y to Y-mm-dd (bank format)

$data = '14/02/2014';
$data_formatada = DateTime::createFromFormat('d/m/Y', $data);
echo $data_formatada->format('Y-m-d') ."<br>";
    
14.02.2014 / 18:26
0

Another option is also the use of the Carbon \ Carbon library created by Brian Nesbitt .

It is installed by default in Laravel. It is an improvement of the DateTime class cited above.

\Carbon\Carbon::createFromFormat('d/m/Y', $data);

Documentation link

    
23.06.2016 / 19:53