lundi 25 février 2019

Date format Conversion with IntlDateFormatter

In one of my form I've got a date datepicker element where the user can enter date

datepicker format is D d MM yyyy

When the form is saved I would like to save the date into the right format :

Y-m-d

In my Laravel Controller, I have a Hook Method which enable me to manipulate data before saved into the table.

The code I wrote to manipulate the format of my date works in http://www.writephponline.com :

$deliverydate = 'Di. 24 Mars 2019'; // Mer. 23 Janvier 2019 OK

$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::NONE, 
IntlDateFormatter::NONE);
$formatter->setPattern('eee dd MMMM y');
$formatter_parse = $formatter->parse($deliverydate);
$deliverydate_formatted = date('Y-m-d', $formatter_parse);

var_dump($deliverydate_formatted);

and return the correct value :

string(10) "2019-03-24"

but not in Laravel which return me :

1970-01-01

No clue why. Would appreciate your expertise. Cheers, Marc



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire