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

ebev89's avatar

Carbon::createFromFormat exception : Unexpected data found data missing

Hello. I am calling the following method to convert date. But getting exception. How can I solve this?

Carbon::createFromFormat('d mmmm, yyyy', $data['date'])
(1/1) InvalidArgumentException
Unexpected data found.
Data missing
in Carbon.php (line 582)
at Carbon::createFromFormat('d mmmm, yyyy', '7 June, 2017')

Thanks.

0 likes
4 replies
tisuchi's avatar

Its because of your provided data and expected formate is not matching.

Not enough data

If your date string is "shorter" than the format string like in this case:

Carbon::createFromFormat('Y-m-d H:i:s', '2017-01-04 00:52');

Carbon will throw:

InvalidArgumentException in Carbon.php line 425: Data missing

Too much data

If your date string is "longer" than the format string like in this case:

 Carbon::createFromFormat('Y-m-d H:i', '2017-01-02 00:27:00');

Carbon will throw:

InvalidArgumentException in Carbon.php line 425: Trailing data

Ref: https://stackoverflow.com/questions/34968061/laravel-carbon-data-missing

2 likes
ebev89's avatar

Thanks for your answer. I already saw this article, but I think the format matches.

'd mmmm, yyyy' = '7 June, 2017'?
1 like
ebev89's avatar

Thanks, worked like a charm. I was confused with javascript.

1 like

Please or to participate in this conversation.