Ryo
Ryo

Reputation: 5

Carbon CreateFromFormat with a localized format

I'm trying to convert my localized date with strftime() to a Carbon object on Laravel.

Here is my code :

$format = Session::get(SESSION_DATE_FORMAT_LOCALIZED);
$dateTime = Carbon::createFromFormat($format, $date);
$format -> "D M j, Y"
$date -> "Ven Décembre 31, 2021"

But it says a textual month could not be found. I tried to use the format with "%" but I get the same error. How can I resolve this?

Upvotes: 0

Views: 1053

Answers (1)

KyleK
KyleK

Reputation: 5121

echo Carbon::createFromLocaleFormat('D F j, Y', 'fr', 'Ven. Décembre 31, 2021');

Short day name/short month names need to match exactly, for instance in French, it's "Ven." not "Ven" for a D format.

Upvotes: 0

Related Questions