Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KikoLdasd's avatar

Error parsing date from string

Hello,

I have a problem with parsing a string in data

ould not parse '28/10/2022 02:02': DateTime::__construct(): Failed to parse time string (28/10/2022 02:02) at position 0 (2): Unexpected character

My code

 $cartProduct['gift_appointment'] = Carbon::parse($cartProduct['additional']['gift_appointment'])->format('Y-d-m H:i:s');

I also tried with createFromFormat but it doesn't work My string comes like "28/10/2022 16:08"

0 likes
1 reply
tykus's avatar

This will work... perhaps you were using the wrong format?

Carbon\Carbon::createFromFormat('d/m/Y H:i', '28/10/2022 16:08');
2 likes

Please or to participate in this conversation.