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.
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
Thanks for your answer. I already saw this article, but I think the format matches.
'd mmmm, yyyy' = '7 June, 2017'?
I think you need to change a bit.
'd F, Y' = '7 June, 2017'?
It will return 7 June, 2017
Here,
d = Day in (01-31) formate
F= Full Month Name ( January )
Y = 4 digit year ( 2017)
Ref: http://php.net/manual/en/function.date.php
Thanks, worked like a charm. I was confused with javascript.
Please sign in or create an account to participate in this conversation.